Skip to content

[HttpFoundation] [Response] Precondition Failed #9803

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 1 commit into from
Closed

[HttpFoundation] [Response] Precondition Failed #9803

wants to merge 1 commit into from

Conversation

lucasmichot
Copy link

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26

This feature adds the counterpart functions of isNotModified() and setNotModified().
When a Request header ETag is provided and doesn't match the Response header Etag
AND/OR
When a Request header If-Modified-Since is provided and doesn't match the Response header Last-Modified

This allows to comply to RFC2616 specifications (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26).

This feature comes with the two following functions:

hasPreconditionFailed()
setPreconditionFailed()

This might ease up conditional response management, especially when using this feature within a REST server.

*
* @return Response
*
* @api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC setting @api tags on non LTS releases is wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for info

see: #9808 (comment) (+1 squashed commit)
Squashed commits:
[7566e01] Use self:: instead of static:: - and I should consider stopping writhing code at midnight after a long workday ;) (+1 squashed commit)
Squashed commits:
[ea1e670] hasPreconditionFailed() and setPreconditionFailed()
*
* @return Response
*/
public function setPreconditionFailed()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we really need this method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasmichot Can you remove this method, which does nothing more than setting the status code? The setNotModified() method is useful as it does more than just setting the status code.

@staabm
Copy link
Contributor

staabm commented Dec 18, 2013

@lucasmichot just thought about the use-case... is there a difference in case a system requests using a etag and the server responds with either 200 ok or 412 precondtion failed?

@stof
Copy link
Member

stof commented Dec 18, 2013

@staabm yes there is. such Etag-based preconditions are meant to be used on non-safe requests, and a 412 would indicate that your edition has been rejected because someone else edited it concurrently already (causing the mismatch). If it responds with 200, you expect the form to be saved

@staabm
Copy link
Contributor

staabm commented Dec 18, 2013

ah ok, though this PR is all about using ETAG in a "write"-context (POST, PUT) instead of "read" (GET)?

@stof
Copy link
Member

stof commented Dec 19, 2013

@staabm It is about write contexts. For a read context, you will not send a precondition-failed response when the ETag does not match. You will send the updated content instead of a 304 (and this is already supported since 2.0)

@staabm
Copy link
Contributor

staabm commented Dec 19, 2013

right, .. was just to make sure that I got it. thanks for the explanation, never used etag in a write context.

@fabpot
Copy link
Member

fabpot commented Dec 28, 2013

looks good to me. @lucasmichot Can you remove the getter before we merge?

@fabpot
Copy link
Member

fabpot commented Dec 28, 2013

Oh, and the tests are broken.

@fabpot
Copy link
Member

fabpot commented Jan 7, 2014

@lucasmichot Do you have some time to finish this PR?

$preconditionFailed = !in_array($this->getEtag(), $etags);

$lastModified = $request->headers->get('If-Modified-Since', false);
$preconditionFailed |= $lastModified !== $this->headers->get('Last-Modified');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should cast to boolean, it's currently an integer. The doc block says it's a boolean

@fabpot
Copy link
Member

fabpot commented Mar 27, 2014

@lucasmichot Can you finish this PR?

*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26
*/
public function hasPreconditionFailed(Request $request)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hasser method should not modify state IMHO. Since this method might change the status code, it's better to name it checkPreconditionFailed.

@fabpot
Copy link
Member

fabpot commented Jun 3, 2014

Closing this PR as there is no feedback. Feel free to reopen it if you decide to finish it. Thanks.

@fabpot fabpot closed this Jun 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants