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

Inherits:
HTTP::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, #stream

Instance Method Summary collapse

Methods included from Connection

#close, #good?, #multiplex, #peer, #read_in_background, #reusable?, #start_connection, #version

Constructor Details

#initialize(stream, *args) ⇒ Server

Returns a new instance of Server.



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

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

Instance Attribute Details

#requestsObject (readonly)

Returns the value of attribute requests.



42
43
44
# File 'lib/async/http/protocol/http2/server.rb', line 42

def requests
  @requests
end

Instance Method Details

#create_stream(stream_id) ⇒ Object



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

def create_stream(stream_id)
	request = Request.new(self, stream_id)
	
	return request.stream
end

#receive_requests(task: Task.current) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/async/http/protocol/http2/server.rb', line 50

def receive_requests(task: Task.current)
	while request = @requests.dequeue
		@count += 1
		
		# We need to close the stream if the user code blows up while generating a response:
		response = begin
			response = yield(request)
		rescue
			request.stream.send_reset_stream(::HTTP::Protocol::HTTP2::INTERNAL_ERROR)
			Async.logger.error(request) {$!}
		else
			request.send_response(response)
		end
	end
end