Class: Landline::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/landline/request.rb

Overview

Request wrapper for Rack protocol

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.

Parameters:

  • env (Array)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/landline/request.rb', line 11

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.from_cookie_string(@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"].dup)
  # File serving path. Public and writable.
  @filepath = "/"
  # Encapsulates all rack variables. Should not be public.
  @rack = init_rack_vars(env)
  # Internal navigation states. Private.
  @states = []
  # Postprocessors for current request
  @postprocessors = []
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



65
66
67
# File 'lib/landline/request.rb', line 65

def cookies
  @cookies
end

#filepathObject

Returns the value of attribute filepath.



68
69
70
# File 'lib/landline/request.rb', line 68

def filepath
  @filepath
end

#headersObject (readonly)

Returns the value of attribute headers.



65
66
67
# File 'lib/landline/request.rb', line 65

def headers
  @headers
end

#paramObject (readonly)

Returns the value of attribute param.



65
66
67
# File 'lib/landline/request.rb', line 65

def param
  @param
end

#pathObject

Returns the value of attribute path.



68
69
70
# File 'lib/landline/request.rb', line 68

def path
  @path
end

#path_infoObject (readonly)

Returns the value of attribute path_info.



65
66
67
# File 'lib/landline/request.rb', line 65

def path_info
  @path_info
end

#postprocessorsObject (readonly)

Returns the value of attribute postprocessors.



65
66
67
# File 'lib/landline/request.rb', line 65

def postprocessors
  @postprocessors
end

#queryObject (readonly)

Returns the value of attribute query.



65
66
67
# File 'lib/landline/request.rb', line 65

def query
  @query
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



65
66
67
# File 'lib/landline/request.rb', line 65

def request_method
  @request_method
end

#script_nameObject (readonly)

Returns the value of attribute script_name.



65
66
67
# File 'lib/landline/request.rb', line 65

def script_name
  @script_name
end

#server_nameObject (readonly)

Returns the value of attribute server_name.



65
66
67
# File 'lib/landline/request.rb', line 65

def server_name
  @server_name
end

#server_portObject (readonly)

Returns the value of attribute server_port.



65
66
67
# File 'lib/landline/request.rb', line 65

def server_port
  @server_port
end

#server_protocolObject (readonly)

Returns the value of attribute server_protocol.



65
66
67
# File 'lib/landline/request.rb', line 65

def server_protocol
  @server_protocol
end

#splatObject (readonly)

Returns the value of attribute splat.



65
66
67
# File 'lib/landline/request.rb', line 65

def splat
  @splat
end

Instance Method Details

#bodynil, String

Returns request body (if POST data exists)

Returns:

  • (nil, String)


45
46
47
# File 'lib/landline/request.rb', line 45

def body
  @body ||= @rack.input&.read
end

#inputIO

Returns raw Rack input object

Returns:

  • (IO)

    (May not entirely be compatible with IO, see Rack/SPEC.rdoc)



51
52
53
# File 'lib/landline/request.rb', line 51

def input
  @rack.input
end

#pop_stateObject

Load last navigation state (path, splat, param) from state stack



61
62
63
# File 'lib/landline/request.rb', line 61

def pop_state
  @path, @param, @splat, @filepath = @states.pop
end

#push_stateObject

Push current navigation state (path, splat, param) onto state stack



56
57
58
# File 'lib/landline/request.rb', line 56

def push_state
  @states.push([@path, @param.dup, @splat.dup, @filepath.dup])
end

#run_postprocessors(response) ⇒ Object

Run postprocessors

Parameters:



37
38
39
40
41
# File 'lib/landline/request.rb', line 37

def run_postprocessors(response)
  @postprocessors.each do |postproc|
    postproc.call(self, response)
  end
end