class Qeweney::RackRequestAdapter

Public Class Methods

new(env) click to toggle source
# File lib/qeweney/rack.rb, line 5
def initialize(env)
  @env = env
  @response_headers = {}
  @response_body = []
end

Public Instance Methods

finish(req) click to toggle source
# File lib/qeweney/rack.rb, line 48
def finish(req)
end
rack_response() click to toggle source
# File lib/qeweney/rack.rb, line 51
def rack_response
  @status = @response_headers.delete(':status')
  [
    @status,
    @response_headers,
    @response_body
  ]
end
request_headers() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/qeweney/rack.rb, line 40
def send_headers(req, headers, empty_response: nil)
  @response_headers = headers
end