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
KEEP_ALIVE =
'keep-alive'.freeze

Constants inherited from HTTP11

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

Instance Attribute Summary

Attributes inherited from HTTP11

#count

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

#persistent?(headers) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#read_body(headers) ⇒ Object



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

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 !persistent?(headers)
		return Body::Remainder.new(@stream)
	end
end

#receive_requestsObject

Server loop.



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

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 persistent?(request.headers) && persistent?(headers)
			@persistent = false
			
			break
		end
	end
	
	return false
end

#versionObject



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

def version
	VERSION
end

#write_body(body, chunked = false) ⇒ Object



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

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