PySide6.QtHttpServer.QHttpServerResponse

class QHttpServerResponse

Encapsulates an HTTP response.

Details

API for creating, reading and modifying a response from an HTTP server, and for writing its contents to a QHttpServerResponder . It has numerous constructors, and static function fromFile for constructing it from the contents of a file. There are functions for setting, getting, and removing headers, and for getting the data, status code and mime type.

Synopsis

Methods

Static functions

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

__init__(statusCode)
Parameters:

statusCodeStatusCode

__init__(data[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:
__init__(data[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:
__init__(data[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:
__init__(data[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:
__init__(data[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:
__init__(mimeType, data[, status=QHttpServerResponder.StatusCode.Ok])
Parameters:
data()
Return type:

QByteArray

Returns the response body.

static fromFile(fileName)
Parameters:

fileName – str

Return type:

QHttpServerResponse

Returns a QHttpServerResponse from the content of the file fileName.

It is the caller’s responsibility to sanity-check the filename, and to have a well-defined policy for which files the server will request.

headers()
Return type:

QHttpHeaders

Returns the currently set HTTP headers.

See also

setHeaders()

mimeType()
Return type:

QByteArray

Returns the value of the HTTP "Content-Type" header.

Note

Default value is "text/html".

setHeaders(newHeaders)
Parameters:

newHeadersQHttpHeaders

statusCode()
Return type:

StatusCode

Returns the status code.

swap(other)
Parameters:

otherQHttpServerResponse

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