PySide6.QtHttpServer.QHttpServerResponder¶
- 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.StatusCode.Continue
QHttpServerResponder.StatusCode.StatusCode.SwitchingProtocols
QHttpServerResponder.StatusCode.StatusCode.Processing
QHttpServerResponder.StatusCode.StatusCode.Ok
QHttpServerResponder.StatusCode.StatusCode.Created
QHttpServerResponder.StatusCode.StatusCode.Accepted
QHttpServerResponder.StatusCode.StatusCode.NonAuthoritativeInformation
QHttpServerResponder.StatusCode.StatusCode.NoContent
QHttpServerResponder.StatusCode.StatusCode.ResetContent
QHttpServerResponder.StatusCode.StatusCode.PartialContent
QHttpServerResponder.StatusCode.StatusCode.MultiStatus
QHttpServerResponder.StatusCode.StatusCode.AlreadyReported
QHttpServerResponder.StatusCode.StatusCode.IMUsed
QHttpServerResponder.StatusCode.StatusCode.MultipleChoices
QHttpServerResponder.StatusCode.StatusCode.MovedPermanently
QHttpServerResponder.StatusCode.StatusCode.Found
QHttpServerResponder.StatusCode.StatusCode.SeeOther
QHttpServerResponder.StatusCode.StatusCode.NotModified
QHttpServerResponder.StatusCode.StatusCode.UseProxy
QHttpServerResponder.StatusCode.StatusCode.TemporaryRedirect
QHttpServerResponder.StatusCode.StatusCode.PermanentRedirect
QHttpServerResponder.StatusCode.StatusCode.BadRequest
QHttpServerResponder.StatusCode.StatusCode.Unauthorized
QHttpServerResponder.StatusCode.StatusCode.PaymentRequired
QHttpServerResponder.StatusCode.StatusCode.Forbidden
QHttpServerResponder.StatusCode.StatusCode.NotFound
QHttpServerResponder.StatusCode.StatusCode.MethodNotAllowed
QHttpServerResponder.StatusCode.StatusCode.NotAcceptable
QHttpServerResponder.StatusCode.StatusCode.ProxyAuthenticationRequired
QHttpServerResponder.StatusCode.StatusCode.RequestTimeout
QHttpServerResponder.StatusCode.StatusCode.Conflict
QHttpServerResponder.StatusCode.StatusCode.Gone
QHttpServerResponder.StatusCode.StatusCode.LengthRequired
QHttpServerResponder.StatusCode.StatusCode.PreconditionFailed
QHttpServerResponder.StatusCode.StatusCode.PayloadTooLarge
QHttpServerResponder.StatusCode.StatusCode.UriTooLong
QHttpServerResponder.StatusCode.StatusCode.UnsupportedMediaType
QHttpServerResponder.StatusCode.StatusCode.RequestRangeNotSatisfiable
QHttpServerResponder.StatusCode.StatusCode.ExpectationFailed
QHttpServerResponder.StatusCode.StatusCode.ImATeapot
QHttpServerResponder.StatusCode.StatusCode.MisdirectedRequest
QHttpServerResponder.StatusCode.StatusCode.UnprocessableEntity
QHttpServerResponder.StatusCode.StatusCode.Locked
QHttpServerResponder.StatusCode.StatusCode.FailedDependency
QHttpServerResponder.StatusCode.StatusCode.UpgradeRequired
QHttpServerResponder.StatusCode.StatusCode.PreconditionRequired
QHttpServerResponder.StatusCode.StatusCode.TooManyRequests
QHttpServerResponder.StatusCode.StatusCode.RequestHeaderFieldsTooLarge
QHttpServerResponder.StatusCode.StatusCode.UnavailableForLegalReasons
QHttpServerResponder.StatusCode.StatusCode.InternalServerError
QHttpServerResponder.StatusCode.StatusCode.NotImplemented
QHttpServerResponder.StatusCode.StatusCode.BadGateway
QHttpServerResponder.StatusCode.StatusCode.ServiceUnavailable
QHttpServerResponder.StatusCode.StatusCode.GatewayTimeout
QHttpServerResponder.StatusCode.StatusCode.HttpVersionNotSupported
QHttpServerResponder.StatusCode.StatusCode.VariantAlsoNegotiates
QHttpServerResponder.StatusCode.StatusCode.InsufficientStorage
QHttpServerResponder.StatusCode.StatusCode.LoopDetected
QHttpServerResponder.StatusCode.StatusCode.NotExtended
QHttpServerResponder.StatusCode.StatusCode.NetworkAuthenticationRequired
QHttpServerResponder.StatusCode.StatusCode.NetworkConnectTimeoutError
- sendResponse(response)¶
- Parameters:
response –
QHttpServerResponse
Sends a HTTP
responseto the client.- swap(other)¶
- Parameters:
other –
QHttpServerResponder
Swaps
QHttpServerResponderotherwith 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 –
QHttpHeadersstatus –
StatusCode
Answers a request with an HTTP status code
statusand HTTP Headersheaders.- write(document[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
document –
QJsonDocumentstatus –
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 –
QIODevicemimeType –
QByteArraystatus –
StatusCode
Answers a request with an HTTP status code
statusand a MIME typemimeType. The I/O devicedataprovides the body of the response. Ifdatais 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 –
QIODeviceheaders –
QHttpHeadersstatus –
StatusCode
Answers a request with an HTTP status code
statusand HTTP headersheaders. The I/O devicedataprovides the body of the response. Ifdatais 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 –
QByteArraymimeType –
QByteArraystatus –
StatusCode
Answers a request with an HTTP status code
status, a MIME typemimeTypeand a bodydata.- write(data, headers[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
data –
QByteArrayheaders –
QHttpHeadersstatus –
StatusCode
Answers a request with an HTTP status code
status, HTTP Headersheadersand a bodydata.Note: This function sets HTTP Content-Length header.
- write(document, headers[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
document –
QJsonDocumentheaders –
QHttpHeadersstatus –
StatusCode
Answers a request with an HTTP status code
status, JSON documentdocumentand HTTP headersheaders.Note: This function sets HTTP Content-Type header as “application/json”.
- writeBeginChunked(mimeType[, status=QHttpServerResponder.StatusCode.Ok])¶
- Parameters:
mimeType –
QByteArraystatus –
StatusCode
Start sending chunks of data with the mime type
mimeTypeand and the given status codestatus. This call must be followed up with an arbitrary number of repeatedwriteChunkcalls and and a single call towriteEndChunked.See also
- writeBeginChunked(headers[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
headers –
QHttpHeadersstatus –
StatusCode
Start sending chunks of data with
headersand and the status codestatus. This call must be followed up with an arbitrary number of repeatedwriteChunkcalls and and a single call towriteEndChunked.See also
- writeBeginChunked(headers, trailerNames[, status=QHttpServerResponder.StatusCode.Ok])
- Parameters:
headers –
QHttpHeaderstrailerNames – .list of QHttpHeaders.WellKnownHeader
status –
StatusCode
Start sending chunks of data with
headersand and the given status codestatus. This call must be followed up with an arbitrary number of repeatedwriteChunkcalls and and a single call towriteEndChunkedwith the same trailers given intrailers.See also
- writeChunk(data)¶
- Parameters:
data –
QByteArray
Write
databack to the client. To be called when data is available to write. This can be called multiple times, but before calling thiswriteBeginChunkedmust called, and afterwardswriteEndChunkedmust be called.See also
- writeEndChunked(data)¶
- Parameters:
data –
QByteArray
Write
databack to the client. Must be preceded by a call towriteBeginChunked.See also
- writeEndChunked(data, trailers)
- Parameters:
data –
QByteArraytrailers –
QHttpHeaders
Write
databack to the client with thetrailersannounced inwriteBeginChunked.See also