Class: Sparrow::HttpMessage Abstract
- Inherits:
-
Object
- Object
- Sparrow::HttpMessage
- Defined in:
- lib/sparrow/http_message.rb
Overview
RequestHttpMessage and ResponseHttpMessage should be used in practice
Wrapper class for either a ::ActiveDispatch::Request or ::Rack::Request instance for the given rack environment. The wrapped class is determined based on the presence of the Rails constant.
Direct Known Subclasses
Constant Summary collapse
- FORM_HASH_KEY =
The rack environment hash key that determines if it is a form hash request
'rack.request.form_hash'
- RACK_INPUT_KEY =
The rack environment hash key to access the input/output
'rack.input'
Instance Attribute Summary collapse
-
#env ⇒ Hash
readonly
The Rack environment.
Instance Method Summary collapse
-
#accept ⇒ Object
The HTTP Accept Header field.
-
#content_type ⇒ Object
The HTTP Content Type Field.
-
#form_hash? ⇒ Boolean
True any values is insides the FORM_HASH_KEY of the rack environment.
-
#initialize(env) ⇒ HttpMessage
constructor
Initializes the HttpMessage.
-
#method_missing(method_name, *args) ⇒ Object
Delegates all unknown method calls to the wrapped request.
-
#path ⇒ String
Requested path within this HTTP message.
-
#request ⇒ Object
Depending on the environment this attribute may either be a [::ActionDispatch::Request], when running in a Rails environment, or a [::Rack::Request] otherwise Encapsulates the Rack env.
Constructor Details
#initialize(env) ⇒ HttpMessage
Initializes the HttpMessage
22 23 24 |
# File 'lib/sparrow/http_message.rb', line 22 def initialize(env) @env = env end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Delegates all unknown method calls to the wrapped request
68 69 70 |
# File 'lib/sparrow/http_message.rb', line 68 def method_missing(method_name, *args) request.public_send(method_name, *args) end |
Instance Attribute Details
#env ⇒ Hash (readonly)
Returns the Rack environment.
17 18 19 |
# File 'lib/sparrow/http_message.rb', line 17 def env @env end |
Instance Method Details
#accept ⇒ Object
The HTTP Accept Header field
54 55 56 |
# File 'lib/sparrow/http_message.rb', line 54 def accept http_header(:accept) end |
#content_type ⇒ Object
The HTTP Content Type Field
61 62 63 |
# File 'lib/sparrow/http_message.rb', line 61 def content_type http_header(:content_type) end |
#form_hash? ⇒ Boolean
Returns true any values is insides the FORM_HASH_KEY of the rack environment.
41 42 43 |
# File 'lib/sparrow/http_message.rb', line 41 def form_hash? env[FORM_HASH_KEY].present? end |
#path ⇒ String
Requested path within this HTTP message
47 48 49 |
# File 'lib/sparrow/http_message.rb', line 47 def path http_header(:path_info) end |
#request ⇒ Object
Depending on the environment this attribute may either be a [::ActionDispatch::Request], when running in a Rails environment, or a [::Rack::Request] otherwise Encapsulates the Rack env.
33 34 35 |
# File 'lib/sparrow/http_message.rb', line 33 def request @request ||= request_class.new(env) end |