From 24ef9c61a39f24c8f5ec4414a4a9d0b6a2bc4283 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 14 Jul 2014 17:38:49 +0200 Subject: [PATCH] improve docs --- netlib/http.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/netlib/http.py b/netlib/http.py index 21cde5386..413c73a11 100644 --- a/netlib/http.py +++ b/netlib/http.py @@ -292,12 +292,17 @@ 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 + if line == "\r\n" or line == "\n": # Possible leftover from previous message line = rfile.readline() if not line: raise HttpErrorConnClosed(502, "Server disconnect.") @@ -312,13 +317,13 @@ 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) else: - content = None # if include_body==False then a None content means the body should be read separately + content = None # if include_body==False then a None content means the body should be read separately return httpversion, code, msg, headers, content