protocol.http.request Module

HTTP conversation objects.

class wpull.protocol.http.request.RawRequest(method=None, resource_path=None, version='HTTP/1.1')[source]

Bases: wpull.protocol.abstract.request.BaseRequest, wpull.protocol.abstract.request.SerializableMixin, wpull.protocol.abstract.request.DictableMixin

Represents an HTTP request.

method

str

The HTTP method in the status line. For example, GET, POST.

resource_path

str

The URL or “path” in the status line.

version

str

The HTTP version in the status line. For example, HTTP/1.0.

fields

namevalue.NameValueRecord

The fields in the HTTP header.

body

body.Body, file-like, None

An optional payload.

encoding

str

The encoding of the status line.

copy()[source]

Return a copy.

parse(data)[source]
parse_status_line(data)[source]

Parse the status line bytes.

Returns:An tuple representing the method, URI, and version.
Return type:tuple
set_continue(offset)[source]

Modify the request into a range request.

to_bytes()[source]
to_dict()[source]
class wpull.protocol.http.request.Request(url=None, method='GET', version='HTTP/1.1')[source]

Bases: wpull.protocol.http.request.RawRequest

Represents a higher level of HTTP request.

address

tuple

An address tuple suitable for socket.connect().

username

str

Username for HTTP authentication.

password

str

Password for HTTP authentication.

parse(data)[source]
prepare_for_send(full_url=False)[source]

Modify the request to be suitable for HTTP server.

Parameters:full_url (bool) – Use full URL as the URI. By default, only the path of the URL is given to the server.
to_dict()[source]
class wpull.protocol.http.request.Response(status_code=None, reason=None, version='HTTP/1.1', request=None)[source]

Bases: wpull.protocol.abstract.request.BaseResponse, wpull.protocol.abstract.request.SerializableMixin, wpull.protocol.abstract.request.DictableMixin

Represents the HTTP response.

status_code

int

The status code in the status line.

status_reason

str

The status reason string in the status line.

version

str

The HTTP version in the status line. For example, HTTP/1.1.

fields

namevalue.NameValueRecord

The fields in the HTTP headers (and trailer, if present).

body

body.Body, file-like, None

The optional payload (without and transfer or content encoding).

request

The corresponding request.

encoding

str

The encoding of the status line.

parse(data)[source]
classmethod parse_status_line(data)[source]

Parse the status line bytes.

Returns:An tuple representing the version, code, and reason.
Return type:tuple
protocol
response_code()[source]
response_message()[source]
to_bytes()[source]
to_dict()[source]