rack-cache icon indicating copy to clipboard operation
rack-cache copied to clipboard

If-None-Match header is ignored on POST requests

Open iblue opened this issue 12 years ago • 7 comments

The title says everything. When I send a GET request to the server, containing an If-None-Match header that matches the ETag, I get a 304 Not Modified response as expected. When I do the same for POST-Requests, I get a full response, even though it has the given ETag.

iblue@raven ~ $ curl "http://testing.example.org/resource.json" -H 'If-None-Match: "11263794d27103747aa3048b8d1ca76d" ' -i
HTTP/1.1 304 Not Modified
Server: nginx/0.7.67
Date: Tue, 01 May 2012 12:33:23 GMT
Connection: keep-alive
Status: 304 Not Modified
X-UA-Compatible: IE=Edge,chrome=1
ETag: "11263794d27103747aa3048b8d1ca76d"
Cache-Control: must-revalidate, private, max-age=0
Set-Cookie: _session_id=82d7a4d488e4bd295902cca2b0e3f0b6; path=/; expires=Wed, 01-May-2013 12:33:23 GMT; HttpOnly
X-Request-Id: 4fc3e3bc9f7cd4c334d815ff6958d2d3
X-Runtime: 0.950690
X-Rack-Cache: miss
iblue@raven ~ $ curl -X POST "http://testing.example.org/resource.json" -H 'If-None-Match: "11263794d27103747aa3048b8d1ca76d" ' -i
HTTP/1.1 200 OK
Server: nginx/0.7.67
Date: Tue, 01 May 2012 12:33:36 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 200 OK
X-UA-Compatible: IE=Edge,chrome=1
ETag: "11263794d27103747aa3048b8d1ca76d"
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: _session_id=82d7a4d488e4bd295902cca2b0e3f0b6; path=/; expires=Wed, 01-May-2013 12:33:36 GMT; HttpOnly
X-Request-Id: b4121c1ba148f4a1212bee429b418a40
X-Runtime: 0.954076
X-Rack-Cache: invalidate, pass

[... Content here ... ]

iblue avatar May 01 '12 12:05 iblue

Rack-cache follows RFC 2616 which describes E-Tag and Last-Modifed headers to be used with GET exclusively, so it called ConditionalGet, http://tools.ietf.org/html/rfc2616#section-9.3

mikhailov avatar May 09 '13 10:05 mikhailov

:+1:

xentek avatar May 13 '13 17:05 xentek

If-None-Match can also be used in both PUT's and POST's. There is nothing in the spec that says it can't: https://tools.ietf.org/html/rfc2616#section-14.26

jkiddo avatar Jun 13 '17 09:06 jkiddo

I also only know it as conditional get ... and always saw it implemented with a GET check ... is there any other library that supports this ? Caching puts/posts seems like a terrible idea ...

grosser avatar Jun 13 '17 13:06 grosser

hmm I guess it can make sense if updating to the same state as before ... would love to see any other library that supports that though so rack-cache is not a 1-off with strange logic ...

grosser avatar Jun 13 '17 13:06 grosser

Conditional PUT's and conditional POST's can be used to create idempotent operations, meaning that ie. the same stuff is not created twice or updates are not processed in wrong order. See for instance https://www.hl7.org/fhir/http.html#cond-update

jkiddo avatar Jun 14 '17 20:06 jkiddo

Yeah, sounds good! Want to make a PR ? ... I imagine it's just removing the right conditional somewhere ...

grosser avatar Jun 14 '17 20:06 grosser