Skip to content

Commit 85253e5

Browse files
committed
[HttpFoundation] Add OTIONS and TRACE to the list of safe methods
1 parent b7ed32a commit 85253e5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Symfony/Component/HttpFoundation/Request.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ public function isMethod($method)
14701470
*/
14711471
public function isMethodSafe()
14721472
{
1473-
return in_array($this->getMethod(), array('GET', 'HEAD'));
1473+
return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
14741474
}
14751475

14761476
/**

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,32 @@ public function getLongHostNames()
19121912
array(str_repeat(':', 101)),
19131913
);
19141914
}
1915+
1916+
/**
1917+
* @dataProvider methodProvider
1918+
*/
1919+
public function testMethodSafe($method, $safe)
1920+
{
1921+
$request = new Request();
1922+
$request->setMethod($method);
1923+
$this->assertEquals($safe, $request->isMethodSafe());
1924+
}
1925+
1926+
public function methodProvider()
1927+
{
1928+
return array(
1929+
array(Request::METHOD_HEAD, true),
1930+
array(Request::METHOD_GET, true),
1931+
array(Request::METHOD_POST, false),
1932+
array(Request::METHOD_PUT, false),
1933+
array(Request::METHOD_PATCH, false),
1934+
array(Request::METHOD_DELETE, false),
1935+
array(Request::METHOD_PURGE, false),
1936+
array(Request::METHOD_OPTIONS, true),
1937+
array(Request::METHOD_TRACE, true),
1938+
array(Request::METHOD_CONNECT, false),
1939+
);
1940+
}
19151941
}
19161942

19171943
class RequestContentProxy extends Request

0 commit comments

Comments
 (0)