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.
39 40 41 42 43 44 45 |
# File 'lib/async/http/server.rb', line 39 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.
47 48 49 |
# File 'lib/async/http/server.rb', line 47 def endpoint @endpoint end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
48 49 50 |
# File 'lib/async/http/server.rb', line 48 def protocol @protocol end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
49 50 51 |
# File 'lib/async/http/server.rb', line 49 def scheme @scheme end |
Class Method Details
.for(*arguments, **options, &block) ⇒ Object
35 36 37 |
# File 'lib/async/http/server.rb', line 35 def self.for(*arguments, **, &block) self.new(block, *arguments, **) end |
Instance Method Details
#accept(peer, address, task: Task.current) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/async/http/server.rb', line 51 def accept(peer, address, task: Task.current) connection = @protocol.server(peer) Console.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 # Console.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 ensure connection&.close end |
#run ⇒ Object
73 74 75 |
# File 'lib/async/http/server.rb', line 73 def run @endpoint.accept(&self.method(:accept)) end |