- class QHttpServerResponder¶
API for sending replies from an HTTP server. More…
Synopsis¶
Methods¶
def
sendResponse()
def
swap()
def
write()
def
writeChunk()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Provides functions for writing back to an HTTP client with overloads for serializing JSON objects. It also has support for writing HTTP headers and status code.
- class StatusCode¶
HTTP status codes
Constant
Description
QHttpServerResponder.StatusCode.Continue
QHttpServerResponder.StatusCode.SwitchingProtocols
QHttpServerResponder.StatusCode.Processing
QHttpServerResponder.StatusCode.Ok
QHttpServerResponder.StatusCode.Created
QHttpServerResponder.StatusCode.Accepted
QHttpServerResponder.StatusCode.NonAuthoritativeInformation
QHttpServerResponder.StatusCode.NoContent
QHttpServerResponder.StatusCode.ResetContent
QHttpServerResponder.StatusCode.PartialContent
QHttpServerResponder.StatusCode.MultiStatus
QHttpServerResponder.StatusCode.AlreadyReported
QHttpServerResponder.StatusCode.IMUsed
QHttpServerResponder.StatusCode.MultipleChoices
QHttpServerResponder.StatusCode.MovedPermanently
QHttpServerResponder.StatusCode.Found
QHttpServerResponder.StatusCode.SeeOther
QHttpServerResponder.StatusCode.NotModified
QHttpServerResponder.StatusCode.UseProxy
QHttpServerResponder.StatusCode.TemporaryRedirect
QHttpServerResponder.StatusCode.PermanentRedirect
QHttpServerResponder.StatusCode.BadRequest
QHttpServerResponder.StatusCode.Unauthorized
QHttpServerResponder.StatusCode.PaymentRequired
QHttpServerResponder.StatusCode.Forbidden
QHttpServerResponder.StatusCode.NotFound
QHttpServerResponder.StatusCode.MethodNotAllowed
QHttpServerResponder.StatusCode.NotAcceptable
QHttpServerResponder.StatusCode.ProxyAuthenticationRequired
QHttpServerResponder.StatusCode.RequestTimeout
QHttpServerResponder.StatusCode.Conflict
QHttpServerResponder.StatusCode.Gone
QHttpServerResponder.StatusCode.LengthRequired
QHttpServerResponder.StatusCode.PreconditionFailed
QHttpServerResponder.StatusCode.PayloadTooLarge
QHttpServerResponder.StatusCode.UriTooLong
QHttpServerResponder.StatusCode.UnsupportedMediaType
QHttpServerResponder.StatusCode.RequestRangeNotSatisfiable
QHttpServerResponder.StatusCode.ExpectationFailed
QHttpServerResponder.StatusCode.ImATeapot
QHttpServerResponder.StatusCode.MisdirectedRequest
QHttpServerResponder.StatusCode.UnprocessableEntity
QHttpServerResponder.StatusCode.Locked
QHttpServerResponder.StatusCode.FailedDependency
QHttpServerResponder.StatusCode.UpgradeRequired
QHttpServerResponder.StatusCode.PreconditionRequired
QHttpServerResponder.StatusCode.TooManyRequests
QHttpServerResponder.StatusCode.RequestHeaderFieldsTooLarge
QHttpServerResponder.StatusCode.UnavailableForLegalReasons
QHttpServerResponder.StatusCode.InternalServerError
QHttpServerResponder.StatusCode.NotImplemented
QHttpServerResponder.StatusCode.BadGateway
QHttpServerResponder.StatusCode.ServiceUnavailable
QHttpServerResponder.StatusCode.GatewayTimeout
QHttpServerResponder.StatusCode.HttpVersionNotSupported
QHttpServerResponder.StatusCode.VariantAlsoNegotiates
QHttpServerResponder.StatusCode.InsufficientStorage
QHttpServerResponder.StatusCode.LoopDetected
QHttpServerResponder.StatusCode.NotExtended
QHttpServerResponder.StatusCode.NetworkAuthenticationRequired
QHttpServerResponder.StatusCode.NetworkConnectTimeoutError
- sendResponse(response)¶
- Parameters:
response –
QHttpServerResponse
Sends a HTTP
response
to the client.- swap(other)¶
- Parameters:
other –
QHttpServerResponder
Swaps
QHttpServerResponder
other
with thisQHttpServerResponder
. This operation is very fast and never fails.- write([status=QHttpServerResponder.StatusCode.Ok])¶
- Parameters:
status –
StatusCode
Answers a request with an HTTP status code
status
.Note: This function sets HTTP Content-Type header as “application/x-empty”.
- write(headers[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
headers –
QHttpHeaders
status –
StatusCode
Answers a request with an HTTP status code
status
and HTTP Headersheaders
.- write(document[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
document –
QJsonDocument
status –
StatusCode
Answers a request with an HTTP status code
status
, and JSON documentdocument
.Note: This function sets HTTP Content-Type header as “application/json”.
- write(data, mimeType[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
data –
QIODevice
mimeType –
QByteArray
status –
StatusCode
Answers a request with an HTTP status code
status
and a MIME typemimeType
. The I/O devicedata
provides the body of the response. Ifdata
is sequential, the body of the message is sent in chunks: otherwise, the function assumes all the content is available and sends it all at once but the read is done in chunks.Note
This function takes the ownership of
data
.- write(data, headers[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
data –
QIODevice
headers –
QHttpHeaders
status –
StatusCode
Answers a request with an HTTP status code
status
and HTTP headersheaders
. The I/O devicedata
provides the body of the response. Ifdata
is sequential, the body of the message is sent in chunks: otherwise, the function assumes all the content is available and sends it all at once but the read is done in chunks.Note
This function takes the ownership of
data
.- write(data, mimeType[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
data –
QByteArray
mimeType –
QByteArray
status –
StatusCode
Answers a request with an HTTP status code
status
, a MIME typemimeType
and a bodydata
.- write(data, headers[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
data –
QByteArray
headers –
QHttpHeaders
status –
StatusCode
Answers a request with an HTTP status code
status
, HTTP Headersheaders
and a bodydata
.Note: This function sets HTTP Content-Length header.
- write(document, headers[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
document –
QJsonDocument
headers –
QHttpHeaders
status –
StatusCode
Answers a request with an HTTP status code
status
, JSON documentdocument
and HTTP headersheaders
.Note: This function sets HTTP Content-Type header as “application/json”.
- writeBeginChunked(mimeType[, status=QHttpServerResponder.StatusCode.Ok])¶
- Parameters:
mimeType –
QByteArray
status –
StatusCode
Start sending chunks of data with the mime type
mimeType
and and the given status codestatus
. This call must be followed up with an arbitrary number of repeatedwriteChunk
calls and and a single call towriteEndChunked
.See also
- writeBeginChunked(headers[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
headers –
QHttpHeaders
status –
StatusCode
Start sending chunks of data with
headers
and and the status codestatus
. This call must be followed up with an arbitrary number of repeatedwriteChunk
calls and and a single call towriteEndChunked
.See also
- writeBeginChunked(headers, trailerNames[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
headers –
QHttpHeaders
trailerNames – .list of QHttpHeaders.WellKnownHeader
status –
StatusCode
Start sending chunks of data with
headers
and and the given status codestatus
. This call must be followed up with an arbitrary number of repeatedwriteChunk
calls and and a single call towriteEndChunked
with the same trailers given intrailers
.See also
- writeChunk(data)¶
- Parameters:
data –
QByteArray
Write
data
back to the client. To be called when data is available to write. This can be called multiple times, but before calling thiswriteBeginChunked
must called, and afterwardswriteEndChunked
must be called.See also
- writeEndChunked(data)¶
- Parameters:
data –
QByteArray
Write
data
back to the client. Must be preceded by a call towriteBeginChunked
.See also
- writeEndChunked(data, trailers)
- Parameters:
data –
QByteArray
trailers –
QHttpHeaders
Write
data
back to the client with thetrailers
announced inwriteBeginChunked
.See also