Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove empty payload from GET requests #1651

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

edgars-vasiljevs
Copy link
Contributor

Currently all Inertia GET requests have Content-Type: application/json header applied because empty object is passed as a payload. Axios sees an object and sets content type to application/json even though request body is empty.

This is an issue because Laravel interprets these requests differently than regular GET request. See here

One example where this is a problem - for example I have GET route and I want to add or update some query parameters in current request using request()->merge(['foo' => 'bar'])

When running request()->query() I expect to get foo parameter back since it is a GET request. Instead I get nothing. This is because merge runs on json input source instead of query. See here and here

Setting data to null is enough for Axios to ignore payload.

@edgars-vasiljevs
Copy link
Contributor Author

edgars-vasiljevs commented Aug 18, 2023

Here is another case

->get(..) method is broken on any request instance derived from original request.

$request = Request::createFrom(request());

request()->merge(['foo1' => 'bar']);
$request->merge(['foo2' => 'bar']);

var_export(request()->get('foo1'));
var_export($request->get('foo2'));

// GET request without content-type "application/json" header
'bar'
'bar'

// GET request with content-type "application/json" header
'bar'
NULL

For example this breaks spatie/laravel-query-builder package since it uses ->get() method internally to get filter/sorting params from query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant