dingo / dingo/api

Internal request with JSON

Open
#1,238 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Doing an internal request from an original request with a payload in JSON causes the internal request to report ->has('parameter') responses from the original request. The problem comes from the fact that the two requests read the JSON data from php://input.

It's curious because ->get('parameter') works fine but I've only traced what ->has() do. Looks like ->get() works with the parameter bag and this one is correctly populated.

To test this do a POST call to a route with a JSON payload like this:

``` javascript
$.ajax({
type: 'POST',
url: '/a-route',
data: {
'foo': 'bar'
},
success: success,
dataType: 'json'
});
```

Then, in that controller, internally call another controller (the method isn't relevant) without passing any parameter:

``` php
\Api::raw()->get('/another-route', [])->getContent();
```

Check the value of ->has() and ->get() in the last controller:

``` php
ddd(\Request::has('foo'), \Request::get('foo'));
```

This is the output:

``` php
\Request::has(...) bool TRUE
\Request::get(...) NULL
```

And the expected output:

``` php
\Request::has(...) bool FALSE
\Request::get(...) NULL
```

A workaround for this is to override the ->has() function on the Request facade and make it check if the ->get() result is empty, but it's very far from elegant.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.