improve docs

This commit is contained in:
Maximilian Hils 2014-07-14 17:38:49 +02:00
parent c78b426c2a
commit 24ef9c61a3

View File

@ -292,9 +292,14 @@ def parse_response_line(line):
return (proto, code, msg)
def read_response(rfile, method, body_size_limit, include_body=True):
def read_response(rfile, request_method, body_size_limit, include_body=True):
"""
Return an (httpversion, code, msg, headers, content) tuple.
By default, both response header and body are read.
If include_body=False is specified, content may be one of the following:
- None, if the response is technically allowed to have a response body
- "", if the response must not have a response body (e.g. it's a response to a HEAD request)
"""
line = rfile.readline()
if line == "\r\n" or line == "\n": # Possible leftover from previous message
@ -312,8 +317,8 @@ def read_response(rfile, method, body_size_limit, include_body=True):
if headers is None:
raise HttpError(502, "Invalid headers.")
# Parse response body according to http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-16#section-3.3
if method in ["HEAD", "CONNECT"] or (code in [204, 304]) or 100 <= code <= 199:
# Parse response body according to http://tools.ietf.org/html/rfc7230#section-3.3
if request_method in ["HEAD", "CONNECT"] or (code in [204, 304]) or 100 <= code <= 199:
content = ""
elif include_body:
content = read_http_body(rfile, headers, body_size_limit, False)