eventlet.green.http package

Submodules

eventlet.green.http.client module

HTTP/1.1 client library

<intro stuff goes here> <other stuff, too>

HTTPConnection goes through a number of “states”, which define when a client may legally make another request or fetch the response for a particular request. This diagram details these state transitions:

(null)

HTTPConnection()

v

Idle

putrequest()

v

Request-started

( putheader() )* endheaders()

v

Request-sent

|_____________________________ | | getresponse() raises | response = getresponse() | ConnectionError v v

Unread-response Idle [Response-headers-read]

|____________________ | | | response.read() | putrequest() v v

Idle Req-started-unread-response

______/|

/ |

response.read() | | ( putheader() )* endheaders()

v v

Request-started Req-sent-unread-response

response.read()

v

Request-sent

This diagram presents the following rules:

– a second request may not be started until {response-headers-read} – a response [object] cannot be retrieved until {request-sent} – there is no differentiation between an unread response body and a

partially read response body

Note: this enforcement is applied by the HTTPConnection class. The

HTTPResponse class does not enforce this state machine, which implies sophisticated clients may accelerate the request/response pipeline. Caution should be taken, though: accelerating the states beyond the above pattern may imply knowledge of the server’s connection-close behavior for certain requests. For example, it is impossible to tell whether the server will close the connection UNTIL the response headers have been read; this means that further requests cannot be placed into the pipeline until it is known that the server will NOT be closing the connection.

Logical State __state __response ————- ——- ———- Idle _CS_IDLE None Request-started _CS_REQ_STARTED None Request-sent _CS_REQ_SENT None Unread-response _CS_IDLE <response_class> Req-started-unread-response _CS_REQ_STARTED <response_class> Req-sent-unread-response _CS_REQ_SENT <response_class>

exception eventlet.green.http.client.BadStatusLine(line)

Bases: HTTPException

exception eventlet.green.http.client.CannotSendHeader

Bases: ImproperConnectionState

exception eventlet.green.http.client.CannotSendRequest

Bases: ImproperConnectionState

class eventlet.green.http.client.HTTPConnection(host, port=None, timeout=<object object>, source_address=None)

Bases: object

auto_open = 1
close()

Close the connection to the HTTP server.

connect()

Connect to the host and port specified in __init__.

debuglevel = 0
default_port = 80
endheaders(message_body=None, **kwds)

Indicate that the last header line has been sent to the server.

This method sends the request to the server. The optional message_body argument can be used to pass a message body associated with the request.

getresponse()

Get the response from the server.

If the HTTPConnection is in the correct state, returns an instance of HTTPResponse or of whatever object is returned by the response_class variable.

If a request has not been sent or if a previous response has not be handled, ResponseNotReady is raised. If the HTTP response indicates that the connection should be closed, then it will be closed before the response is returned. When the connection is closed, the underlying socket is closed.

putheader(header, *values)

Send a request header line to the server.

For example: h.putheader(‘Accept’, ‘text/html’)

putrequest(method, url, skip_host=0, skip_accept_encoding=0)

Send a request to the server.

`method’ specifies an HTTP request method, e.g. ‘GET’. `url’ specifies the object being requested, e.g. ‘/index.html’. `skip_host’ if True does not add automatically a ‘Host:’ header `skip_accept_encoding’ if True does not add automatically an

‘Accept-Encoding:’ header

request(method, url, body=None, headers={}, **kwds)

Send a complete request to the server.

response_class

alias of HTTPResponse

send(data)

Send data’ to the server. ``data` can be a string object, a bytes object, an array object, a file-like object that supports a .read() method, or an iterable object.

set_debuglevel(level)
set_tunnel(host, port=None, headers=None)

Set up host and port for HTTP CONNECT tunnelling.

In a connection that uses HTTP CONNECT tunneling, the host passed to the constructor is used as a proxy server that relays all communication to the endpoint passed to set_tunnel. This done by sending an HTTP CONNECT request to the proxy server when the connection is established.

This method must be called before the HTML connection has been established.

The headers argument should be a mapping of extra HTTP headers to send with the CONNECT request.

exception eventlet.green.http.client.HTTPException

Bases: Exception

class eventlet.green.http.client.HTTPResponse(sock, debuglevel=0, method=None, url=None)

Bases: BufferedIOBase

begin()
close()

Flush and close the IO object.

This method has no effect if the file is already closed.

fileno()

Return underlying file descriptor if one exists.

Raise OSError if the IO object does not use a file descriptor.

flush()

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

getcode()

Return the HTTP status code that was sent with the response, or None if the URL is not an HTTP URL.

getheader(name, default=None)

Returns the value of the header matching name.

If there are multiple matching headers, the values are combined into a single string separated by commas and spaces.

If no matching header is found, returns default or None if the default is not specified.

If the headers are unknown, raises http.client.ResponseNotReady.

getheaders()

Return list of (header, value) tuples.

geturl()

Return the real URL of the page.

In some cases, the HTTP server redirects a client to another URL. The urlopen() function handles this transparently, but in some cases the caller needs to know which URL the client was redirected to. The geturl() method can be used to get at this redirected URL.

info()

Returns an instance of the class mimetools.Message containing meta-information associated with the URL.

When the method is HTTP, these headers are those returned by the server at the head of the retrieved HTML page (including Content-Length and Content-Type).

When the method is FTP, a Content-Length header will be present if (as is now usual) the server passed back a file length in response to the FTP retrieval request. A Content-Type header will be present if the MIME type can be guessed.

When the method is local-file, returned headers will include a Date representing the file’s last-modified time, a Content-Length giving file size, and a Content-Type containing a guess at the file’s type. See also the description of the mimetools module.

isclosed()

True if the connection is closed.

peek(n=-1)
read(amt=None)

Read and return up to n bytes.

If the size argument is omitted, None, or negative, read and return all data until EOF.

If the size argument is positive, and the underlying raw stream is not ‘interactive’, multiple raw reads may be issued to satisfy the byte count (unless EOF is reached first). However, for interactive raw streams (as well as sockets and pipes), at most one raw read will be issued, and a short result does not imply that EOF is imminent.

Return an empty bytes object on EOF.

Return None if the underlying raw stream was open in non-blocking mode and no data is available at the moment.

read1(n=-1)

Read with at most one underlying system call. If at least one byte is buffered, return that instead.

readable()

Always returns True

readinto(b)

Read up to len(b) bytes into bytearray b and return the number of bytes read.

readline(limit=-1)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

class eventlet.green.http.client.HTTPSConnection(host, port=None, key_file=None, cert_file=None, timeout=<object object>, source_address=None, *, context=None, check_hostname=None)

Bases: HTTPConnection

This class allows communication via SSL.

connect()

Connect to a host on a given (SSL) port.

default_port = 443
exception eventlet.green.http.client.ImproperConnectionState

Bases: HTTPException

exception eventlet.green.http.client.IncompleteRead(partial, expected=None)

Bases: HTTPException

exception eventlet.green.http.client.InvalidURL

Bases: HTTPException

exception eventlet.green.http.client.LineTooLong(line_type)

Bases: HTTPException

exception eventlet.green.http.client.NotConnected

Bases: HTTPException

exception eventlet.green.http.client.RemoteDisconnected(*pos, **kw)

Bases: ConnectionResetError, BadStatusLine

exception eventlet.green.http.client.ResponseNotReady

Bases: ImproperConnectionState

exception eventlet.green.http.client.UnimplementedFileMode

Bases: HTTPException

exception eventlet.green.http.client.UnknownProtocol(version)

Bases: HTTPException

exception eventlet.green.http.client.UnknownTransferEncoding

Bases: HTTPException

eventlet.green.http.client.error

alias of HTTPException

eventlet.green.http.cookiejar module

eventlet.green.http.cookies module

eventlet.green.http.server module

Module contents

class eventlet.green.http.HTTPStatus(*values)

Bases: IntEnum

HTTP status codes and reason phrases

Status codes from the following RFCs are all observed:

  • RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616

  • RFC 6585: Additional HTTP Status Codes

  • RFC 3229: Delta encoding in HTTP

  • RFC 4918: HTTP Extensions for WebDAV, obsoletes 2518

  • RFC 5842: Binding Extensions to WebDAV

  • RFC 7238: Permanent Redirect

  • RFC 2295: Transparent Content Negotiation in HTTP

  • RFC 2774: An HTTP Extension Framework

ACCEPTED = 202
ALREADY_REPORTED = 208
BAD_GATEWAY = 502
BAD_REQUEST = 400
CONFLICT = 409
CONTINUE = 100
CREATED = 201
EXPECTATION_FAILED = 417
FAILED_DEPENDENCY = 424
FORBIDDEN = 403
FOUND = 302
GATEWAY_TIMEOUT = 504
GONE = 410
HTTP_VERSION_NOT_SUPPORTED = 505
IM_USED = 226
INSUFFICIENT_STORAGE = 507
INTERNAL_SERVER_ERROR = 500
LENGTH_REQUIRED = 411
LOCKED = 423
LOOP_DETECTED = 508
METHOD_NOT_ALLOWED = 405
MOVED_PERMANENTLY = 301
MULTIPLE_CHOICES = 300
MULTI_STATUS = 207
NETWORK_AUTHENTICATION_REQUIRED = 511
NON_AUTHORITATIVE_INFORMATION = 203
NOT_ACCEPTABLE = 406
NOT_EXTENDED = 510
NOT_FOUND = 404
NOT_IMPLEMENTED = 501
NOT_MODIFIED = 304
NO_CONTENT = 204
OK = 200
PARTIAL_CONTENT = 206
PAYMENT_REQUIRED = 402
PERMANENT_REDIRECT = 308
PRECONDITION_FAILED = 412
PRECONDITION_REQUIRED = 428
PROCESSING = 102
PROXY_AUTHENTICATION_REQUIRED = 407
REQUESTED_RANGE_NOT_SATISFIABLE = 416
REQUEST_ENTITY_TOO_LARGE = 413
REQUEST_HEADER_FIELDS_TOO_LARGE = 431
REQUEST_TIMEOUT = 408
REQUEST_URI_TOO_LONG = 414
RESET_CONTENT = 205
SEE_OTHER = 303
SERVICE_UNAVAILABLE = 503
SWITCHING_PROTOCOLS = 101
TEMPORARY_REDIRECT = 307
TOO_MANY_REQUESTS = 429
UNAUTHORIZED = 401
UNPROCESSABLE_ENTITY = 422
UNSUPPORTED_MEDIA_TYPE = 415
UPGRADE_REQUIRED = 426
USE_PROXY = 305
VARIANT_ALSO_NEGOTIATES = 506