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

Uri->method() is not picking up X-HTTP-METHOD-OVERRIDE request headers #2847

Closed
hughbris opened this issue Mar 9, 2020 · 1 comment
Closed

Comments

@hughbris
Copy link
Contributor

hughbris commented Mar 9, 2020

I am sending "faked PUT" requests using POST method and header X-HTTP-METHOD-OVERRIDE:PUT, but the dumped uri.method is still "POST". I can see why: it's because PHP is presenting the headers with different names to what the code is matching:

        if ($method === 'POST' && isset($_SERVER['X-HTTP-METHOD-OVERRIDE'])) {

Dumping $_SERVER and using Inspector, I see the header is expressed by PHP as $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] instead.

For context, I'm using a template as a REST endpoint, and GET and POST are working just fine. I am sending the requests with JQuery.ajax() and the request leaves them intact. In Twig, I have a simple branch to handle different HTTP methods like:

{% if uri.method|lower == 'get' %}
...
{% elseif uri.method|lower == 'put' %}
...
{% elseif uri.method|lower == 'post' %}
...
{% endif %}

A previous attempt sent a real PUT request, but I found there was no way to access the request parameters or the request body/payload. Then I tried a fake PUT with my own attempt to read the header, but didn't seem to be able to access that either (for the request).

Then I dug into the source code and found that line, which looks like it should have done the heavy lifting of faking PUT for me.

My research suggests PHP is doing the header key rewriting. Is this always done, or only for Ajax requests? Looks like Uri->getContentType() would fail to match in a similar way.

Some comments [1] [2] allude to PHP mangling header names and this being standard. I'm having trouble following. Might help.

rhukster added a commit that referenced this issue Mar 13, 2020
@rhukster
Copy link
Member

I think you are correct, it does look like the proper syntax per the spec is the lower case version with dashes, but PHP uses the uppercase with underscores.

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

No branches or pull requests

2 participants