Skip to content

Commit

Permalink
bug #19321 [HttpFoundation] Add OPTIONS and TRACE to the list of safe…
Browse files Browse the repository at this point in the history
… methods (dunglas)

This PR was squashed before being merged into the 2.7 branch (closes #19321).

Discussion
----------

[HttpFoundation] Add OPTIONS and TRACE to the list of safe methods

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

According to [RFC 7231](https://tools.ietf.org/html/rfc7231#section-8.1.3) `OPTIONS` and `TRACE` are safe methods.

Commits
-------

1404607 [HttpFoundation] Add OPTIONS and TRACE to the list of safe methods
  • Loading branch information
fabpot committed Jul 10, 2016
2 parents 8b6d74e + 1404607 commit 500c2cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1470,7 +1470,7 @@ public function isMethod($method)
*/
public function isMethodSafe()
{
return in_array($this->getMethod(), array('GET', 'HEAD'));
return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -1912,6 +1912,32 @@ public function getLongHostNames()
array(str_repeat(':', 101)),
);
}

/**
* @dataProvider methodSafeProvider
*/
public function testMethodSafe($method, $safe)
{
$request = new Request();
$request->setMethod($method);
$this->assertEquals($safe, $request->isMethodSafe());
}

public function methodSafeProvider()
{
return array(
array('HEAD', true),
array('GET', true),
array('POST', false),
array('PUT', false),
array('PATCH', false),
array('DELETE', false),
array('PURGE', false),
array('OPTIONS', true),
array('TRACE', true),
array('CONNECT', false),
);
}
}

class RequestContentProxy extends Request
Expand Down

0 comments on commit 500c2cd

Please sign in to comment.