Class: Async::HTTP::Mock::Endpoint
- Inherits:
-
Object
- Object
- Async::HTTP::Mock::Endpoint
- Defined in:
- lib/async/http/mock/endpoint.rb
Overview
This is an endpoint which bridges a client with a local server.
Instance Attribute Summary collapse
-
#authority ⇒ Object
readonly
Returns the value of attribute authority.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
Instance Method Summary collapse
-
#connect ⇒ Object
Create a new client-side connection by enqueuing the server-side socket.
-
#initialize(protocol = Protocol::HTTP2, scheme = "http", authority = "localhost", queue: Queue.new) ⇒ Endpoint
constructor
Initialize a mock endpoint for testing.
-
#run(parent: Task.current) {|::HTTP::Protocol::Request| ... } ⇒ Object
Processing incoming connections.
-
#wrap(endpoint) ⇒ Object
Create a new mock endpoint that shares the same connection queue but adopts another endpoint’s scheme and authority.
Constructor Details
#initialize(protocol = Protocol::HTTP2, scheme = "http", authority = "localhost", queue: Queue.new) ⇒ Endpoint
Initialize a mock endpoint for testing.
20 21 22 23 24 25 26 |
# File 'lib/async/http/mock/endpoint.rb', line 20 def initialize(protocol = Protocol::HTTP2, scheme = "http", = "localhost", queue: Queue.new) @protocol = protocol @scheme = scheme @authority = @queue = queue end |
Instance Attribute Details
#authority ⇒ Object (readonly)
Returns the value of attribute authority.
30 31 32 |
# File 'lib/async/http/mock/endpoint.rb', line 30 def @authority end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
28 29 30 |
# File 'lib/async/http/mock/endpoint.rb', line 28 def protocol @protocol end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
29 30 31 |
# File 'lib/async/http/mock/endpoint.rb', line 29 def scheme @scheme end |
Instance Method Details
#connect ⇒ Object
Create a new client-side connection by enqueuing the server-side socket.
46 47 48 49 50 51 52 |
# File 'lib/async/http/mock/endpoint.rb', line 46 def connect local, remote = ::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) @queue.enqueue(remote) return local end |
#run(parent: Task.current) {|::HTTP::Protocol::Request| ... } ⇒ Object
Processing incoming connections
34 35 36 37 38 39 40 41 42 |
# File 'lib/async/http/mock/endpoint.rb', line 34 def run(parent: Task.current, &block) while peer = @queue.dequeue server = @protocol.server(peer) parent.async do server.each(&block) end end end |
#wrap(endpoint) ⇒ Object
Create a new mock endpoint that shares the same connection queue but adopts another endpoint’s scheme and authority.
57 58 59 |
# File 'lib/async/http/mock/endpoint.rb', line 57 def wrap(endpoint) self.class.new(@protocol, endpoint.scheme, endpoint., queue: @queue) end |