Class: Async::HTTP::Protocol::HTTP2::Server

Inherits:
Protocol::HTTP2::Server
  • Object
show all
Includes:
Connection
Defined in:
lib/async/http/protocol/http2/server.rb

Instance Attribute Summary collapse

Attributes included from Connection

#count, #promises, #stream

Instance Method Summary collapse

Methods included from Connection

#connected?, #http1?, #http2?, #multiplex, #peer, #read_in_background, #reusable?, #start_connection, #version, #write_frame

Constructor Details

#initialize(stream) ⇒ Server

Returns a new instance of Server.



34
35
36
37
38
39
40
41
42
# File 'lib/async/http/protocol/http2/server.rb', line 34

def initialize(stream)
	@stream = stream
	
	framer = ::Protocol::HTTP2::Framer.new(stream)
	
	super(framer)
	
	@requests = Async::Queue.new
end

Instance Attribute Details

#requestsObject (readonly)

Returns the value of attribute requests.



44
45
46
# File 'lib/async/http/protocol/http2/server.rb', line 44

def requests
  @requests
end

Instance Method Details

#accept_stream(stream_id) ⇒ Object

A new request has come in:



47
48
49
50
51
# File 'lib/async/http/protocol/http2/server.rb', line 47

def accept_stream(stream_id)
	super do
		Request.new(self, stream_id)
	end
end

#each(task: Task.current) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/async/http/protocol/http2/server.rb', line 59

def each(task: Task.current)
	while request = @requests.dequeue
		@count += 1
		
		task.async do
			begin
				response = yield(request)
			rescue
				# We need to close the stream if the user code blows up while generating a response:
				request.stream.send_reset_stream(::Protocol::HTTP2::INTERNAL_ERROR)
				
				raise
			else
				request.send_response(response)
			end
		end
	end
end

#stop_connection(error) ⇒ Object



53
54
55
56
57
# File 'lib/async/http/protocol/http2/server.rb', line 53

def stop_connection(error)
	super
	
	@requests.enqueue nil
end