Class: Async::HTTP::Protocol::HTTP1

Inherits:
IO::Protocol::Line
  • Object
show all
Defined in:
lib/async/http/protocol/http1.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,
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ HTTP1

Returns a new instance of HTTP1.



36
37
38
# File 'lib/async/http/protocol/http1.rb', line 36

def initialize(stream)
	super(stream, HTTP11::CRLF)
end

Class Method Details

.client(*args) ⇒ Object



41
42
43
# File 'lib/async/http/protocol/http1.rb', line 41

def client(*args)
	HTTP11.new(*args)
end

Instance Method Details

#create_handler(version) ⇒ Object



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

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

#receive_requests(&block) ⇒ Object



56
57
58
59
60
# File 'lib/async/http/protocol/http1.rb', line 56

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