diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e19301d7..e9a72619c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file. For info on - Add fallback lookup and deprecation warning for obsolete status symbols. ([#2137](https://github.com/rack/rack/pull/2137), [@wtn]) - In `Rack::Files`, ignore the `Range` header if served file is 0 bytes. ([#2159](https://github.com/rack/rack/pull/2159), [@zarqman]) - rack.early_hints is now officially supported as an optional feature (already implemented by Unicorn, Puma, and Falcon). ([#1831](https://github.com/rack/rack/pull/1831), [@casperisfine, @jeremyevans]) +- Deprecate automatic cache invalidation in `Request#{GET,POST}` ([#2073](https://github.com/rack/rack/pull/2073) ([@jeremyevans]) - Only cookie keys that are not valid according to the HTTP specifications are escaped. We are planning to deprecate this behaviour, so now a deprecation message will be emitted in this case. In the future, invalid cookie keys may not be accepted. ([#2191](https://github.com/rack/rack/pull/2191), [@ioquatix]) ## [3.0.11] - 2024-05-10 diff --git a/lib/rack/request.rb b/lib/rack/request.rb index 5b8eb91e5..b880b6ec8 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -482,9 +482,14 @@ def parseable_data? # Returns the data received in the query string. def GET - if get_header(RACK_REQUEST_QUERY_STRING) == query_string + rr_query_string = get_header(RACK_REQUEST_QUERY_STRING) + query_string = self.query_string + if rr_query_string == query_string get_header(RACK_REQUEST_QUERY_HASH) else + if rr_query_string + warn "query string used for GET parsing different from current query string. Starting in Rack 3.2, Rack will used the cached GET value instead of parsing the current query string.", uplevel: 1 + end query_hash = parse_query(query_string, '&') set_header(RACK_REQUEST_QUERY_STRING, query_string) set_header(RACK_REQUEST_QUERY_HASH, query_hash) @@ -505,9 +510,12 @@ def POST # If the form hash was already memoized: if form_hash = get_header(RACK_REQUEST_FORM_HASH) + form_input = get_header(RACK_REQUEST_FORM_INPUT) # And it was memoized from the same input: - if get_header(RACK_REQUEST_FORM_INPUT).equal?(rack_input) + if form_input.equal?(rack_input) return form_hash + elsif form_input + warn "input stream used for POST parsing different from current input stream. Starting in Rack 3.2, Rack will used the cached POST value instead of parsing the current input stream.", uplevel: 1 end end diff --git a/test/spec_request.rb b/test/spec_request.rb index 24d0e692e..ce6ceef1f 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -851,7 +851,7 @@ def initialize(*) req.media_type.must_be_nil end - it "cache, but invalidates the cache" do + deprecated "cache, but invalidates the cache" do req = make_request \ Rack::MockRequest.env_for("/?foo=quux", "CONTENT_TYPE" => "application/x-www-form-urlencoded",