Class: Request::Rack
Overview
Rack request
Constant Summary collapse
- SERVER_PORT =
Key.new('SERVER_PORT')
- REQUEST_METHOD =
Key.new('REQUEST_METHOD')
- RACK_URL_SCHEME =
Key.new('rack.url_scheme')
- IF_MODIFIED_SINCE =
Key.new('HTTP_IF_MODIFIED_SINCE')
- CONTENT_LENGTH =
Key.new('CONTENT_LENGTH')
- InvalidKeyError =
Error raised when an invalid rack env key is accessed
Class.new(RuntimeError)
- CONTENT_LENGTH_REGEXP =
/\A[0-9]+\z/.freeze
Constants inherited from Request
Instance Attribute Summary collapse
-
#rack_env ⇒ Hash
readonly
private
Return rack env.
Instance Method Summary collapse
-
#content_length ⇒ Fixnum
private
Return content length.
-
#if_modified_since ⇒ Time?
private
Return if modified since.
-
#initialize(rack_env) ⇒ undefined
constructor
private
Initialize object.
-
#port ⇒ Fixnum
private
Return http port.
-
#protocol ⇒ Protocol
private
Return request protocol.
-
#query_params ⇒ Array
private
Return query params.
-
#request_method ⇒ Method
private
Return request method.
Methods inherited from Request
#absolute_uri, #absolute_uri_path, #host, #host_with_port, #path_info, #query_params_hash, #query_string, #root_uri, #uid
Constructor Details
#initialize(rack_env) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize object
22 23 24 |
# File 'lib/request/rack.rb', line 22 def initialize(rack_env) @rack_env = rack_env end |
Instance Attribute Details
#rack_env ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return rack env
32 33 34 |
# File 'lib/request/rack.rb', line 32 def rack_env @rack_env end |
Instance Method Details
#content_length ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return content length
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/request/rack.rb', line 91 def content_length value = @rack_env.fetch(CONTENT_LENGTH) do return 0 end unless value =~ CONTENT_LENGTH_REGEXP raise InvalidKeyError, 'invalid content length' end value.to_i end |
#if_modified_since ⇒ Time?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return if modified since
125 126 127 128 129 130 131 132 |
# File 'lib/request/rack.rb', line 125 def if_modified_since value = @rack_env.fetch(IF_MODIFIED_SINCE) { return } begin Time.httpdate(value) rescue ArgumentError nil end end |
#port ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return http port
56 57 58 |
# File 'lib/request/rack.rb', line 56 def port @rack_env.fetch(SERVER_PORT).to_i(10) end |
#protocol ⇒ Protocol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return request protocol
67 68 69 |
# File 'lib/request/rack.rb', line 67 def protocol Protocol.get(access(RACK_URL_SCHEME)) end |
#query_params ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return query params
110 111 112 |
# File 'lib/request/rack.rb', line 110 def query_params Addressable::URI.form_unencode(query_string) end |
#request_method ⇒ Method
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return request method
78 79 80 |
# File 'lib/request/rack.rb', line 78 def request_method Method.get(access(REQUEST_METHOD)) end |