diff --git a/Gemfile.lock b/Gemfile.lock index c60465a..51cd933 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ PATH http_parser.rb (~> 0.6.0) msgpack (~> 1.4.2) polyphony (~> 0.64) - qeweney (~> 0.10.0) + qeweney (~> 0.11) rack (>= 2.0.8, < 2.3.0) websocket (~> 1.2.8) @@ -52,7 +52,7 @@ GEM msgpack (1.4.2) multipart-post (2.1.1) polyphony (0.64) - qeweney (0.10) + qeweney (0.11) escape_utils (~> 1.2.1) rack (2.2.3) rake (12.3.3) diff --git a/lib/tipi/rack_adapter.rb b/lib/tipi/rack_adapter.rb index 1dec531..ebb45ff 100644 --- a/lib/tipi/rack_adapter.rb +++ b/lib/tipi/rack_adapter.rb @@ -3,25 +3,7 @@ require 'rack' module Tipi - module RackAdapter - # Implements a rack input stream: - # https://www.rubydoc.info/github/rack/rack/master/file/SPEC#label-The+Input+Stream - class InputStream - def initialize(request) - @request = request - end - - def gets; end - - def read(length = nil, outbuf = nil); end - - def each(&block) - @request.each_chunk(&block) - end - - def rewind; end - end - + module RackAdapter class << self def run(app) ->(req) { respond(req, app.(env(req))) } @@ -32,41 +14,8 @@ def load(path) instance_eval(src, path, 1) end - RACK_ENV = { - 'SCRIPT_NAME' => '', - 'rack.version' => Rack::VERSION, - '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 - } - def env(request) - Hash.new do |h, k| - h[k] = env_value_from_request(request, k) - end - end - - HTTP_HEADER_RE = /^HTTP_(.+)$/.freeze - - def env_value_from_request(request, key) - case key - when 'REQUEST_METHOD' then request.method - 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.downcase] - else RACK_ENV[key] - end + Qeweney.rack_env_from_request(request) end def respond(request, (status_code, headers, body)) diff --git a/tipi.gemspec b/tipi.gemspec index 25c638f..18e9e22 100644 --- a/tipi.gemspec +++ b/tipi.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.executables = ['tipi'] s.add_runtime_dependency 'polyphony', '~>0.64' - s.add_runtime_dependency 'qeweney', '~>0.10.0' + s.add_runtime_dependency 'qeweney', '~>0.11' s.add_runtime_dependency 'http_parser.rb', '~>0.6.0' s.add_runtime_dependency 'http-2', '~>0.10.0'