Class: Async::HTTP::Server
- Inherits:
-
Protocol::HTTP::Middleware
- Object
- Protocol::HTTP::Middleware
- Async::HTTP::Server
- Defined in:
- lib/async/http/server.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
Class Method Summary collapse
Instance Method Summary collapse
- #accept(peer, address, task: Task.current) ⇒ Object
-
#initialize(app, endpoint, protocol = endpoint.protocol, scheme = endpoint.scheme) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(app, endpoint, protocol = endpoint.protocol, scheme = endpoint.scheme) ⇒ Server
Returns a new instance of Server.
34 35 36 37 38 39 40 |
# File 'lib/async/http/server.rb', line 34 def initialize(app, endpoint, protocol = endpoint.protocol, scheme = endpoint.scheme) super(app) @endpoint = endpoint @protocol = protocol @scheme = scheme end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
42 43 44 |
# File 'lib/async/http/server.rb', line 42 def endpoint @endpoint end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
43 44 45 |
# File 'lib/async/http/server.rb', line 43 def protocol @protocol end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
44 45 46 |
# File 'lib/async/http/server.rb', line 44 def scheme @scheme end |
Class Method Details
.for(*args, &block) ⇒ Object
30 31 32 |
# File 'lib/async/http/server.rb', line 30 def self.for(*args, &block) self.new(block, *args) end |
Instance Method Details
#accept(peer, address, task: Task.current) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/async/http/server.rb', line 46 def accept(peer, address, task: Task.current) stream = Async::IO::Stream.new(peer) connection = @protocol.server(stream) Async.logger.debug(self) {"Incoming connnection from #{address.inspect} to #{@protocol}"} connection.each do |request| # We set the default scheme unless it was otherwise specified. # https://tools.ietf.org/html/rfc7230#section-5.5 request.scheme ||= self.scheme # This is a slight optimization to avoid having to get the address from the socket. request.remote_address = address # Async.logger.debug(self) {"Incoming request from #{address.inspect}: #{request.method} #{request.path}"} # If this returns nil, we assume that the connection has been hijacked. self.call(request) end end |
#run ⇒ Object
67 68 69 |
# File 'lib/async/http/server.rb', line 67 def run @endpoint.accept(&self.method(:accept)) end |