summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Rosenberg <aarongrosenberg@gmail.com>2021-06-05 11:37:31 -0500
committerJeremy Evans <code@jeremyevans.net>2021-11-03 12:00:27 -0900
commit62ceaa04698a786e4779197d05b16f91f61f28bf (patch)
tree76fa0607d40ca4cfd076b3960820816398c2a64a
parente0993d47096d36535dbe725091963a7e0f5aab52 (diff)
downloadrack-62ceaa04698a786e4779197d05b16f91f61f28bf.tar.gz
Revert "Flatten Rack::Request::Env into Request"
This reverts commit d96b5c39fd32aa8f8b1b694470a0f78f4a7475fe.
-rw-r--r--CHANGELOG.md3
-rw-r--r--lib/rack/request.rb106
2 files changed, 58 insertions, 51 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fbe7987b..b007127b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,7 +34,8 @@ All notable changes to this project will be documented in this file. For info on
- Handle cookies with values that end in '=' ([#1645](https://github.com/rack/rack/pull/1645), [@lukaso](https://github.com/lukaso))
- Fix multipart filename generation for filenames that contain spaces. Encode spaces as "%20" instead of "+" which will be decoded properly by the multipart parser. ([#1736](https://github.com/rack/rack/pull/1645), [@muirdm](https://github.com/muirdm))
- `Rack::Request#scheme` returns `ws` or `wss` when one of the `X-Forwarded-Scheme` / `X-Forwarded-Proto` headers is set to `ws` or `wss`, respectively. ([#1730](https://github.com/rack/rack/issues/1730), [@erwanst](https://github.com/erwanst))
-- `Rack::Request::Env#initialize` does not need to call `super()`. This was leftover from the creation of the `Env` module. Flatten the `Env` module into `Request` as it is unused outside. ([#1751](https://github.com/rack/rack/pull/1751)), [@agrberg](https://github.com/agrberg))
+- `Rack::Request::Env#initialize` does not need to call `super()`. This was leftover from the creation of the `Env` module. ~~Flatten the `Env` module into `Request` as it is unused outside.~~ ([#1751](https://github.com/rack/rack/pull/1751), [@agrberg](https://github.com/agrberg))
+- Restore Rails compatibility. `Rack::Request::Env` is included in `ActionDispatch::Request`. ([#1755](https://github.com/rack/rack/pull/1755), [@agrberg](https://github.com/agrberg))
## [2.2.3] - 2020-06-15
diff --git a/lib/rack/request.rb b/lib/rack/request.rb
index b8f21213..2a47c7ad 100644
--- a/lib/rack/request.rb
+++ b/lib/rack/request.rb
@@ -17,10 +17,6 @@ module Rack
end
self.ip_filter = lambda { |ip| /\A127\.0\.0\.1\Z|\A(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\.|\A::1\Z|\Afd[0-9a-f]{2}:.+|\Alocalhost\Z|\Aunix\Z|\Aunix:/i.match?(ip) }
-
- # The environment of the request.
- attr_reader :env
-
ALLOWED_SCHEMES = %w(https http wss ws).freeze
SCHEME_WHITELIST = ALLOWED_SCHEMES
if Object.respond_to?(:deprecate_constant)
@@ -28,8 +24,8 @@ module Rack
end
def initialize(env)
- @env = env
@params = nil
+ super(env)
end
def params
@@ -47,59 +43,68 @@ module Rack
v
end
- # Predicate method to test to see if `name` has been set as request
- # specific data
- def has_header?(name)
- @env.key? name
- end
+ module Env
+ # The environment of the request.
+ attr_reader :env
- # Get a request specific value for `name`.
- def get_header(name)
- @env[name]
- end
+ def initialize(env)
+ @env = env
+ end
- # If a block is given, it yields to the block if the value hasn't been set
- # on the request.
- def fetch_header(name, &block)
- @env.fetch(name, &block)
- end
+ # Predicate method to test to see if `name` has been set as request
+ # specific data
+ def has_header?(name)
+ @env.key? name
+ end
- # Loops through each key / value pair in the request specific data.
- def each_header(&block)
- @env.each(&block)
- end
+ # Get a request specific value for `name`.
+ def get_header(name)
+ @env[name]
+ end
- # Set a request specific value for `name` to `v`
- def set_header(name, v)
- @env[name] = v
- end
+ # If a block is given, it yields to the block if the value hasn't been set
+ # on the request.
+ def fetch_header(name, &block)
+ @env.fetch(name, &block)
+ end
- # Add a header that may have multiple values.
- #
- # Example:
- # request.add_header 'Accept', 'image/png'
- # request.add_header 'Accept', '*/*'
- #
- # assert_equal 'image/png,*/*', request.get_header('Accept')
- #
- # http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
- def add_header(key, v)
- if v.nil?
- get_header key
- elsif has_header? key
- set_header key, "#{get_header key},#{v}"
- else
- set_header key, v
+ # Loops through each key / value pair in the request specific data.
+ def each_header(&block)
+ @env.each(&block)
end
- end
- # Delete a request specific value for `name`.
- def delete_header(name)
- @env.delete name
- end
+ # Set a request specific value for `name` to `v`
+ def set_header(name, v)
+ @env[name] = v
+ end
+
+ # Add a header that may have multiple values.
+ #
+ # Example:
+ # request.add_header 'Accept', 'image/png'
+ # request.add_header 'Accept', '*/*'
+ #
+ # assert_equal 'image/png,*/*', request.get_header('Accept')
+ #
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
+ def add_header(key, v)
+ if v.nil?
+ get_header key
+ elsif has_header? key
+ set_header key, "#{get_header key},#{v}"
+ else
+ set_header key, v
+ end
+ end
- def initialize_copy(other)
- @env = other.env.dup
+ # Delete a request specific value for `name`.
+ def delete_header(name)
+ @env.delete name
+ end
+
+ def initialize_copy(other)
+ @env = other.env.dup
+ end
end
module Helpers
@@ -637,6 +642,7 @@ module Rack
end
end
+ include Env
include Helpers
end
end