Class: Qeweney::RackRequestAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/qeweney/rack.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ RackRequestAdapter

Returns a new instance of RackRequestAdapter.



5
6
7
8
9
# File 'lib/qeweney/rack.rb', line 5

def initialize(env)
  @env = env
  @response_headers = {}
  @response_body = []
end

Instance Method Details

#finish(req) ⇒ Object



48
49
# File 'lib/qeweney/rack.rb', line 48

def finish(req)
end

#rack_responseObject



51
52
53
54
55
56
57
58
# File 'lib/qeweney/rack.rb', line 51

def rack_response
  @status = @response_headers.delete(':status')
  [
    @status,
    @response_headers,
    @response_body
  ]
end

#request_headersObject



11
12
13
14
15
16
17
# File 'lib/qeweney/rack.rb', line 11

def request_headers
  request_http_headers.merge(
    ':scheme' => @env['rack.url_scheme'],
    ':method' => @env['REQUEST_METHOD'].downcase,
    ':path' => request_path_from_env
  )
end

#request_http_headersObject



25
26
27
28
29
30
31
32
33
# File 'lib/qeweney/rack.rb', line 25

def request_http_headers
  headers = {}
  @env.each do |k, v|
    next unless k =~ /^HTTP_(.+)$/

    headers[Regexp.last_match(1).downcase.gsub('_', '-')] = v
  end
  headers
end

#request_path_from_envObject



19
20
21
22
23
# File 'lib/qeweney/rack.rb', line 19

def request_path_from_env
  path = File.join(@env['SCRIPT_NAME'], @env['PATH_INFO'])
  path = path + "?#{@env['QUERY_STRING']}" if @env['QUERY_STRING']
  path
end

#respond(req, body, headers) ⇒ Object



35
36
37
38
# File 'lib/qeweney/rack.rb', line 35

def respond(req, body, headers)
  @response_body << body
  @response_headers = headers
end

#send_chunk(req, body, done: false) ⇒ Object



44
45
46
# File 'lib/qeweney/rack.rb', line 44

def send_chunk(req, body, done: false)
  @response_body << body
end

#send_headers(req, headers, empty_response: nil) ⇒ Object



40
41
42
# File 'lib/qeweney/rack.rb', line 40

def send_headers(req, headers, empty_response: nil)
  @response_headers = headers
end