lib/hi/server.rb in hi-1.0.0 vs lib/hi/server.rb in hi-1.1.0
- old
+ new
@@ -1,17 +1,18 @@
require 'awesome_print'
+require 'hi/request'
module Hi
class Server
attr_reader :port
def initialize(port = nil)
@port = (port = port.to_i) > 0 ? port : 3000
end
def call(env)
- log parse_request(env)
+ log Hi::Request.new(env).to_h
[ 200, { 'Content-Type' => 'text/plain' }, ['hi'] ]
end
private
@@ -19,28 +20,8 @@
def log(request)
unless ENV['RACK_ENV'] == 'test'
ap "#{request[:request_method]} #{request[:url]} (#{Time.now})"
ap request
end
- end
-
- def parse_request(env)
- request = Rack::Request.new(env)
-
- {
- host: request.host,
- ip: request.ip,
- port: request.port,
- request_method: request.request_method,
- scheme: request.scheme,
- url: request.url,
- query_string: request.query_string,
- body: request.body.string,
- content_length: request.content_length,
- media_type: request.media_type,
- referer: request.referer,
- user_agent: request.user_agent,
- xhr: request.xhr?,
- }
end
end
end