Class: Async::HTTP::Protocol::HTTP1x

Inherits:
IO::Protocol::Line
  • Object
show all
Defined in:
lib/async/http/protocol/http1x.rb

Overview

A server that supports both HTTP1.0 and HTTP1.1 semantics by detecting the version of the request.

Constant Summary collapse

HANDLERS =
{
	"HTTP/1.0" => HTTP10,
	"HTTP/1.1" => HTTP11,
}

Instance Method Summary collapse

Constructor Details

#initialize(stream, handlers: HANDLERS) ⇒ HTTP1x

Returns a new instance of HTTP1x.



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

def initialize(stream, handlers: HANDLERS)
	super(stream, HTTP11::CRLF)
	
	@handlers = handlers
	
	@handler = nil
end

Instance Method Details

#create_handler(version) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/async/http/protocol/http1x.rb', line 42

def create_handler(version)
	if klass = @handlers[version]
		klass.new(@stream)
	else
		raise RuntimeError, "Unsupported protocol version #{version}"
	end
end

#receive_requests(&block) ⇒ Object



50
51
52
53
54
# File 'lib/async/http/protocol/http1x.rb', line 50

def receive_requests(&block)
	method, path, version = self.peek_line.split(/\s+/, 3)
	
	create_handler(version).receive_requests(&block)
end

#send_request(request, &block) ⇒ Object



56
57
58
# File 'lib/async/http/protocol/http1x.rb', line 56

def send_request(request, &block)
	create_handler(request.version).send_request(request, &block)
end