Module: Qeweney

Defined in:
lib/qeweney.rb,
lib/qeweney/rack.rb,
lib/qeweney/status.rb,
lib/qeweney/request.rb,
lib/qeweney/routing.rb,
lib/qeweney/version.rb,
lib/qeweney/response.rb,
lib/qeweney/mime_types.rb,
lib/qeweney/request_info.rb,
lib/qeweney/test_adapter.rb

Defined Under Namespace

Modules: MimeTypes, RequestInfoClassMethods, RequestInfoMethods, ResponseMethods, RoutingMethods, StaticFileCaching, Status Classes: InputStream, RackRequestAdapter, Request, TestAdapter

Constant Summary collapse

RACK_ENV =

TODO: improve conformance to rack spec TODO: set values like port, scheme etc from actual connection

{
  'SCRIPT_NAME'                    => '',
  'rack.version'                   => [1, 3],
  'SERVER_PORT'                    => '80', # ?
  'rack.url_scheme'                => 'http', # ?
  'rack.errors'                    => STDERR, # ?
  'rack.multithread'               => false,
  'rack.run_once'                  => false,
  'rack.hijack?'                   => false,
  'rack.hijack'                    => nil,
  'rack.hijack_io'                 => nil,
  'rack.session'                   => nil,
  'rack.logger'                    => nil,
  'rack.multipart.buffer_size'     => nil,
  'rack.multipar.tempfile_factory' => nil
}
HTTP_HEADER_RE =
/^HTTP_(.+)$/.freeze
VERSION =
'0.18'

Class Method Summary collapse

Class Method Details

.rack(&block) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/qeweney/rack.rb', line 61

def self.rack(&block)
  proc do |env|
    adapter = RackRequestAdapter.new(env)
    req = Request.new(adapter.request_headers, adapter)
    block.(req)
    adapter.rack_response
  end
end

.rack_env_from_request(request) ⇒ Object



89
90
91
92
93
# File 'lib/qeweney/rack.rb', line 89

def self.rack_env_from_request(request)
  Hash.new do |h, k|
    h[k] = rack_env_value_from_request(request, k)
  end
end

.rack_env_value_from_request(request, key) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/qeweney/rack.rb', line 116

def self.rack_env_value_from_request(request, key)
  case key
  when 'REQUEST_METHOD' then request.method.upcase
  when 'PATH_INFO'      then request.path
  when 'QUERY_STRING'   then request.query_string || ''
  when 'SERVER_NAME'    then request.headers['host']
  when 'rack.input'     then InputStream.new(request)
  when HTTP_HEADER_RE   then request.headers[$1.gsub('_', '-').downcase]
  else                       RACK_ENV[key]
  end
end

.route(&block) ⇒ Object



4
5
6
# File 'lib/qeweney/routing.rb', line 4

def self.route(&block)
  ->(r) { r.route(&block) }
end