Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Add Request::isMethodIdempotent method #19322

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 12 src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ public function isMethod($method)
}

/**
* Checks whether the method is safe or not.
* Checks whether or not the method is safe.
*
* @return bool
*/
Expand All @@ -1482,6 +1482,16 @@ public function isMethodSafe()
return in_array($this->getMethod(), array('GET', 'HEAD'));
}

/**
* Checks whether or not the method is idempotent.
*
* @return bool
*/
public function isMethodIdempotent()
{
return in_array($this->getMethod(), array('HEAD', 'GET', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'PURGE'));
}

/**
* Returns the request body content.
*
Expand Down
26 changes: 26 additions & 0 deletions 26 src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,32 @@ public function getLongHostNames()
array(str_repeat(':', 101)),
);
}

/**
* @dataProvider methodIdempotentProvider
*/
public function testMethodIdempotent($method, $idempotent)
{
$request = new Request();
$request->setMethod($method);
$this->assertEquals($idempotent, $request->isMethodIdempotent());
}

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

class RequestContentProxy extends Request
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.