Pyjo.Transaction.HTTP - HTTP transaction¶
import Pyjo.Transaction.HTTP
# Client
tx = Pyjo.Transaction.HTTP.new()
tx.req.method = 'GET'
tx.req.url.parse('http://example.com')
tx.req.headers.accept = 'application/json'
print(tx.res.code)
print(tx.res.headers.content_type)
print(tx.res.body)
print(tx.remote_address)
Pyjo.Transaction.HTTP
is a container for HTTP transactions based on
RFC 7230 and
RFC 7231.
Events¶
Pyjo.Transaction.HTTP
inherits all events from Pyjo.Transaction
and
can emit the following new ones.
request¶
@tx.on
def request(tx):
...
Emitted when a request is ready and needs to be handled.
@tx.on
def request(tx):
tx.res.headers.header('X-Bender', 'Bite my shiny metal ass!')
unexpected¶
@tx.on
def unexpected(tx, res):
...
Emitted for unexpected 1xx
responses that will be ignored.
@tx.on
def unexpected(tx, res):
@tx.res.on
def finish():
print('Follow-up response is finished.')
upgrade¶
@tx.on
def upgrade(tx, ws):
...
Emitted when transaction gets upgraded to a Pyjo.Transaction.WebSocket
object.
@tx.on
def upgrade(tx, ws):
ws.res.headers.header('X-Bender', 'Bite my shiny metal ass!')
Classes¶
-
class
Pyjo.Transaction.HTTP.
Pyjo_Transaction_HTTP
(**kwargs)¶ Pyjo.Transaction.HTTP
inherits all attributes and methods fromPyjo.Transaction
and implements the following new ones.-
client_read
(chunk)¶ tx.client_read(chunk)
Read data client-side, used to implement user agents.
-
client_write
()¶ chunk = tx.client_write
Write data client-side, used to implement user agents.
-
is_empty
¶ boolean = tx.is_empty
Check transaction for
HEAD
request and1xx
,204
or304
response.
-
keep_alive
¶ boolean = tx.keep_alive
Check if connection can be kept alive.
-
previous
= None¶ previous = tx.previous tx.previous = Pyjo.Transaction.HTTP.new()
Previous transaction that triggered this follow-up transaction, usually a
Pyjo.Transaction.HTTP
object.# Paths of previous requests print(tx.previous.previous.req.url.path) print(tx.previous.req.url.path)
-
redirects
¶ redirects = tx.redirects
Return a list of all previous transactions that preceded this follow-up transaction.
# Paths of all previous requests for redir in tx.redirects: print(redir.req.url.path)
-
server_read
(chunk)¶ tx.server_read(chunk)
Read data server-side, used to implement web servers.
-
server_write
()¶ chunk = tx.server_write()
Write data server-side, used to implement web servers.
-
-
Pyjo.Transaction.HTTP.
object
¶ alias of
Pyjo_Transaction_HTTP