Skip to content

X-HTTP-Method-Override header doesn't appear to be working #641

@torohill

Description

@torohill

Here's the behaviour I'm seeing with Slim 2.3.1, PHP 5.4.4 and Apache 2.2.22. The request below ends up being a POST rather than a GET. Perhaps I'm missing something but this isn't working as I would expect.

Request:
curl -v -X POST http://localhost/ -H "X-HTTP-Method-Override: GET"

This means that the header is set with an HTTP_ prefix in $_SERVER:
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'GET';

The HTTP_ prefixed value is extracted in \Slim\Http\Headers::extract() and set in the environment in \Slim\Environment::__construct() at line 166.

Then in \Slim\Middleware\MethodOverride::call() the environment is checked for X_HTTP_METHOD_OVERRIDE, so it doesn't find the HTTP_ prefixed header.

There is some code at line 172 in \Slim\Environment::_construct() that used to copy the HTTP prefixed values and remove the prefix, but that is currently commented out.

It looks like this code was commented out in this revision (codeguy@6b83ccd) and replaced with the \Slim\Http\Headers::extract() method, but the functionality was subtly altered at the same time.

Here are couple of possible fixes, not sure which is the best approach:

  1. Restore the code which copies the HTTP_ prefixes values and removes the prefix. This could possibly just be applied to HTTP_X_ values.
  2. Use getallheaders() to retrieve the headers and add to the environment. Either in addition to the HTTP_ headers from $SERVER or instead of. getallheaders() returns the headers without the HTTP prefix.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions