Class: Async::HTTP::Protocol::HTTP10

Inherits:
HTTP11
  • Object
show all
Defined in:
lib/async/http/protocol/http10.rb

Overview

Implements basic HTTP/1.1 request/response.

Constant Summary collapse

VERSION =
"HTTP/1.0".freeze

Constants inherited from HTTP11

Async::HTTP::Protocol::HTTP11::CLOSE, Async::HTTP::Protocol::HTTP11::CRLF, Async::HTTP::Protocol::HTTP11::KEEP_ALIVE

Instance Method Summary collapse

Methods inherited from HTTP11

#call, #initialize, #multiplex, #read_request, #read_response, #reusable?, #write_request, #write_response

Constructor Details

This class inherits a constructor from Async::HTTP::Protocol::HTTP11

Instance Method Details

#keep_alive?(headers) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/async/http/protocol/http10.rb', line 34

def keep_alive?(headers)
	headers['connection'] == KEEP_ALIVE
end

#read_body(headers) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/async/http/protocol/http10.rb', line 62

def read_body(headers)
	if body = super
		return body
	end
	
	# Technically, with HTTP/1.0, if no content-length is specified, we just need to read everything until the connection is closed.
	if !keep_alive?(headers)
		return Body::Remainder.new(@stream)
	end
end

#receive_requestsObject

Server loop.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/async/http/protocol/http10.rb', line 39

def receive_requests
	while request = Request.new(*self.read_request)
		response = yield request
		
		response.version ||= request.version
		
		write_response(response.version, response.status, response.headers, response.body)
		
		unless keep_alive?(request.headers) && keep_alive?(headers)
			@keep_alive = false
			
			break
		end
	end
	
	return false
end

#versionObject



30
31
32
# File 'lib/async/http/protocol/http10.rb', line 30

def version
	VERSION
end

#write_body(body, chunked = true) ⇒ Object



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

def write_body(body, chunked = true)
	# We don't support chunked encoding.
	super(body, false)
end