lib/falcon/server.rb in falcon-0.9.0 vs lib/falcon/server.rb in falcon-0.10.0
- old
+ new
@@ -16,10 +16,12 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
+require_relative 'input'
+
require 'async/http/server'
module Falcon
class Server < Async::HTTP::Server
def initialize(app, *args)
@@ -34,19 +36,14 @@
def handle_request(request, peer, address)
request_path, query_string = request.path.split('?', 2)
server_name, server_port = (request.authority || '').split(':', 2)
- input = StringIO.new(request.body || '')
- input.set_encoding(Encoding::BINARY)
-
- headers = request.headers.to_http_hash
-
env = {
'rack.version' => [2, 0, 0],
- 'rack.input' => input,
+ 'rack.input' => Input.new(request.body),
'rack.errors' => $stderr,
'rack.multithread' => true,
'rack.multiprocess' => true,
'rack.run_once' => false,
@@ -68,10 +65,18 @@
'rack.url_scheme' => 'http',
# I'm not sure what sane defaults should be here:
'SERVER_NAME' => server_name || '',
'SERVER_PORT' => server_port || '',
- }.merge(headers)
+ }
+
+ if content_type = request.headers['content-type']
+ env['CONTENT_TYPE'] = content_type
+ end
+
+ request.headers.each do |key, value|
+ env["HTTP_#{key.upcase.tr('-', '_')}"] = value
+ end
env['rack.hijack?'] = true
env['rack.hijack'] = lambda do
env['rack.hijack_io'] = peer
end