rack-cache
rack-cache copied to clipboard
If-None-Match header is ignored on POST requests
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 ... ]
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
:+1:
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
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 ...
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 ...
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
Yeah, sounds good! Want to make a PR ? ... I imagine it's just removing the right conditional somewhere ...