Class: Landline::Request
- Inherits:
-
Object
- Object
- Landline::Request
- Defined in:
- lib/landline/request.rb
Overview
Request wrapper for Rack protocol
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#path ⇒ Object
Returns the value of attribute path.
-
#path_info ⇒ Object
readonly
Returns the value of attribute path_info.
-
#postprocessors ⇒ Object
readonly
Returns the value of attribute postprocessors.
-
#query ⇒ Object
Returns the value of attribute query.
-
#rack ⇒ Object
readonly
Returns the value of attribute rack.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#script_name ⇒ Object
readonly
Returns the value of attribute script_name.
-
#server_name ⇒ Object
readonly
Returns the value of attribute server_name.
-
#server_port ⇒ Object
readonly
Returns the value of attribute server_port.
-
#server_protocol ⇒ Object
readonly
Returns the value of attribute server_protocol.
-
#splat ⇒ Object
readonly
Returns the value of attribute splat.
Instance Method Summary collapse
-
#body ⇒ nil, String
Returns request body (if POST data exists).
-
#env ⇒ Object
Reconstructs rack env after modification.
-
#hijack ⇒ Object
Returns full hijack callback.
-
#hijack? ⇒ Boolean
Checks if response stream can be partially hijacked.
-
#initialize(env) ⇒ Request
constructor
A new instance of Request.
-
#input ⇒ IO
Returns raw Rack input object.
-
#pop_state ⇒ Object
Load last navigation state (path, splat, param) from state stack.
-
#push_state ⇒ Object
Push current navigation state (path, splat, param) onto state stack.
-
#run_postprocessors(response) ⇒ Object
Run postprocessors.
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/landline/request.rb', line 12 def initialize(env) # Should not be used under regular circumstances or depended upon. @_original_env = env # Rack environment variable bindings. Should be public and frozen. init_request_params(env) # Cookie hash @cookies = Landline::Cookie.(@headers['cookie']) # Query parsing @query = Landline::Util::Query.new(@query_string) # Pattern matching parameters. Public, readable, unfrozen. @param = {} @splat = [] # Traversal route. Public and writable. @path = URI.decode_www_form_component(env["PATH_INFO"]) # File serving path. Public and writable. @filepath = "/" # Encapsulates all rack variables. Is no longer private, but usually should not be used directly @rack = init_rack_vars(env) # Internal navigation states. Private. @states = [] # Postprocessors for current request @postprocessors = [] # Execution context @context = init_context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def context @context end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def @cookies end |
#filepath ⇒ Object
Returns the value of attribute filepath.
98 99 100 |
# File 'lib/landline/request.rb', line 98 def filepath @filepath end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def headers @headers end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def param @param end |
#path ⇒ Object
Returns the value of attribute path.
98 99 100 |
# File 'lib/landline/request.rb', line 98 def path @path end |
#path_info ⇒ Object (readonly)
Returns the value of attribute path_info.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def path_info @path_info end |
#postprocessors ⇒ Object (readonly)
Returns the value of attribute postprocessors.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def postprocessors @postprocessors end |
#query ⇒ Object
Returns the value of attribute query.
98 99 100 |
# File 'lib/landline/request.rb', line 98 def query @query end |
#rack ⇒ Object (readonly)
Returns the value of attribute rack.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def rack @rack end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def request_method @request_method end |
#script_name ⇒ Object (readonly)
Returns the value of attribute script_name.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def script_name @script_name end |
#server_name ⇒ Object (readonly)
Returns the value of attribute server_name.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def server_name @server_name end |
#server_port ⇒ Object (readonly)
Returns the value of attribute server_port.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def server_port @server_port end |
#server_protocol ⇒ Object (readonly)
Returns the value of attribute server_protocol.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def server_protocol @server_protocol end |
#splat ⇒ Object (readonly)
Returns the value of attribute splat.
95 96 97 |
# File 'lib/landline/request.rb', line 95 def splat @splat end |
Instance Method Details
#body ⇒ nil, String
reads data from rack.input, which is not rewindable. .body data is memoized.
Returns request body (if POST data exists)
51 52 53 |
# File 'lib/landline/request.rb', line 51 def body @body ||= @rack.input&.read end |
#env ⇒ Object
Reconstructs rack env after modification
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/landline/request.rb', line 83 def env path = @path @_original_env.merge(reconstruct_headers) .merge({ 'PATH_INFO' => path, 'REQUEST_PATH' => path, 'QUERY_STRING' => query.query, 'REQUEST_URI' => "#{path}?#{query.query}" }) .merge() end |
#hijack ⇒ Object
Returns full hijack callback
78 79 80 |
# File 'lib/landline/request.rb', line 78 def hijack @_original_env['rack.hijack'] end |
#hijack? ⇒ Boolean
Checks if response stream can be partially hijacked
73 74 75 |
# File 'lib/landline/request.rb', line 73 def hijack? @_original_env['rack.hijack?'] end |
#input ⇒ IO
Rack IO is not always rewindable - if it is read once, the data is gone (i.e. request.body will return nothing).
Returns raw Rack input object
58 59 60 |
# File 'lib/landline/request.rb', line 58 def input @rack.input end |
#pop_state ⇒ Object
Load last navigation state (path, splat, param) from state stack
68 69 70 |
# File 'lib/landline/request.rb', line 68 def pop_state @path, @param, @splat, @filepath = @states.pop end |
#push_state ⇒ Object
Push current navigation state (path, splat, param) onto state stack
63 64 65 |
# File 'lib/landline/request.rb', line 63 def push_state @states.push([@path, @param.dup, @splat.dup, @filepath.dup]) end |
#run_postprocessors(response) ⇒ Object
Run postprocessors
40 41 42 43 44 45 46 |
# File 'lib/landline/request.rb', line 40 def run_postprocessors(response) @context.origin.properties.lookup = {} @postprocessors.reverse_each do |postproc| @context.instance_exec(self, response, &postproc) end @postprocessors = [] end |