lib/net/http/server/daemon.rb in net-http-server-0.2.2 vs lib/net/http/server/daemon.rb in net-http-server-0.2.3
- old
+ new
@@ -24,26 +24,23 @@
# Maximum number of simultaneous connections.
MAX_CONNECTIONS = 256
# Creates a new HTTP Daemon.
#
- # @param [Hash] options
- # Options for the daemon.
- #
- # @option options [String] :host (DEFAULT_HOST)
+ # @param [String] host
# The host to run on.
#
- # @option options [String] :port (DEFAULT_PORT)
+ # @param [String] port
# The port to listen on.
#
- # @option options [Integer] :max_connections (MAX_CONNECTIONS)
+ # @param [Integer] max_connections
# The maximum number of simultaneous connections.
#
- # @option options [IO] :log ($stderr)
+ # @param [IO] log
# The log to write errors to.
#
- # @option options [#call] :handler
+ # @param [#call] handler
# The HTTP Request Handler object.
#
# @yield [request, socket]
# If a block is given, it will be used to process HTTP Requests.
#
@@ -51,19 +48,22 @@
# The HTTP Request.
#
# @yieldparam [TCPSocket] socket
# The TCP socket of the client.
#
- def initialize(options={},&block)
- host = options.fetch(:host,DEFAULT_HOST)
- port = options.fetch(:port,DEFAULT_PORT).to_i
- max_connections = options.fetch(:max_connections,MAX_CONNECTIONS)
- log = options.fetch(:log,$stderr)
+ # @raise [ArgumentError]
+ # No `handler:` value was given.
+ #
+ def initialize(host: DEFAULT_HOST,
+ port: DEFAULT_PORT,
+ max_connections: MAX_CONNECTIONS,
+ log: $stderr,
+ handler: nil,
+ &block)
+ super(port.to_i,host,max_connections,log,false,true)
- super(port,host,max_connections,log,false,true)
-
- handler(options[:handler],&block)
+ handler(handler,&block)
end
#
# Sets the HTTP Request Handler.
#
@@ -104,10 +104,10 @@
if (raw_request = read_request(socket))
parser = Parser.new
begin
request = parser.parse(raw_request)
- rescue Parslet::ParseFailed => error
+ rescue Parslet::ParseFailed
return Responses::BAD_REQUEST
end
normalize_request(request)