PySide6.QtHttpServer.QHttpServerResponder

class QHttpServerResponder

API for sending replies from an HTTP server. More

Synopsis

Methods

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:

responseQHttpServerResponse

Sends a HTTP response to the client.

swap(other)
Parameters:

otherQHttpServerResponder

Swaps QHttpServerResponder other with this QHttpServerResponder . This operation is very fast and never fails.

write([status=QHttpServerResponder.StatusCode.Ok])
Parameters:

statusStatusCode

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:

Answers a request with an HTTP status code status and HTTP Headers headers.

write(document[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

Answers a request with an HTTP status code status, and JSON document document.

Note: This function sets HTTP Content-Type header as “application/json”.

write(data, mimeType[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

Answers a request with an HTTP status code status and a MIME type mimeType. The I/O device data provides the body of the response. If data 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:

Answers a request with an HTTP status code status and HTTP headers headers. The I/O device data provides the body of the response. If data 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:

Answers a request with an HTTP status code status, a MIME type mimeType and a body data.

write(data, headers[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

Answers a request with an HTTP status code status, HTTP Headers headers and a body data.

Note: This function sets HTTP Content-Length header.

write(document, headers[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

Answers a request with an HTTP status code status, JSON document document and HTTP headers headers.

Note: This function sets HTTP Content-Type header as “application/json”.

writeBeginChunked(mimeType[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

Start sending chunks of data with the mime type mimeType and and the given status code status. This call must be followed up with an arbitrary number of repeated writeChunk calls and and a single call to writeEndChunked.

writeBeginChunked(headers[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

Start sending chunks of data with headers and and the status code status. This call must be followed up with an arbitrary number of repeated writeChunk calls and and a single call to writeEndChunked.

writeBeginChunked(headers, trailerNames[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:

Start sending chunks of data with headers and and the given status code status. This call must be followed up with an arbitrary number of repeated writeChunk calls and and a single call to writeEndChunked with the same trailers given in trailers.

writeChunk(data)
Parameters:

dataQByteArray

Write data back to the client. To be called when data is available to write. This can be called multiple times, but before calling this writeBeginChunked must called, and afterwards writeEndChunked must be called.

writeEndChunked(data)
Parameters:

dataQByteArray

Write data back to the client. Must be preceded by a call to writeBeginChunked.

writeEndChunked(data, trailers)
Parameters:

Write data back to the client with the trailers announced in writeBeginChunked.