Class: Qeweney::RackRequestAdapter
- Inherits:
-
Object
- Object
- Qeweney::RackRequestAdapter
- Defined in:
- lib/qeweney/rack.rb
Instance Method Summary collapse
- #finish(req) ⇒ Object
-
#initialize(env) ⇒ RackRequestAdapter
constructor
A new instance of RackRequestAdapter.
- #rack_response ⇒ Object
- #request_headers ⇒ Object
- #request_http_headers ⇒ Object
- #request_path_from_env ⇒ Object
- #respond(req, body, headers) ⇒ Object
- #send_chunk(req, body, done: false) ⇒ Object
- #send_headers(req, headers, empty_response: nil) ⇒ Object
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_response ⇒ Object
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_headers ⇒ Object
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_headers ⇒ Object
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_env ⇒ Object
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 |