PySide6.QtHttpServer.QAbstractHttpServer

class QAbstractHttpServer

API to subclass to implement an HTTP server. More

Inheritance diagram of PySide6.QtHttpServer.QAbstractHttpServer

Inherited by: QHttpServer

Synopsis

Methods

Virtual 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

Subclass this class and override handleRequest() and missingHandler() to create an HTTP server. Use bind() to start listening to all the incoming connections to a server.

This is a low level API, see QHttpServer for a highler level API to implement an HTTP server.

__init__([parent=None])
Parameters:

parentQObject

Creates an instance of QAbstractHttpServer with the parent parent.

bind(server)
Parameters:

serverQLocalServer

Return type:

bool

Bind the HTTP server to given QLocalServer server over which the transmission happens. It is possible to call this function multiple times with different instances of server to handle multiple connections.

After calling this function, every _new_ connection will be handled and forwarded by the HTTP server.

It is the user’s responsibility to call QLocalServer::listen() on the server before calling this function. If server is not listening, nothing will happen and false will be returned.

If the server is nullptr false is returned.

If successful the server will be parented to this HTTP server and true is returned.

See also

listen()

bind(server)
Parameters:

serverQTcpServer

Return type:

bool

Bind the HTTP server to given TCP server over which the transmission happens. It is possible to call this function multiple times with different instances of TCP server to handle multiple connections and ports, for example both SSL and non-encrypted connections.

After calling this function, every _new_ connection will be handled and forwarded by the HTTP server.

It is the user’s responsibility to call QTcpServer::listen() on the server before calling this function. If server is not listening, nothing will happen and false will be returned.

If successful the server will be parented to this HTTP server and true is returned.

To allow usage of HTTP 2, bind to a QSslServer where QSslConfiguration::setAllowedNextProtocols() has been called with the arguments { QSslConfiguration::ALPNProtocolHTTP2 }.

See also

setAllowedNextProtocols()

abstract handleRequest(request, responder)
Parameters:
Return type:

bool

Override this function to handle each incoming request, by examining the request and sending the appropriate response back to responder. Return true if the request was handled successfully. If this method returns false, missingHandler() will be called afterwards.

This function must move out of responder before returning true.

http2Configuration()
Return type:

QHttp2Configuration

Returns server’s HTTP/2 configuration parameters.

localServers()
Return type:

.list of QLocalServer

Returns the local servers of this HTTP server.

See also

serverPorts()

abstract missingHandler(request, responder)
Parameters:

Override this function to handle each incoming request that was not handled by handleRequest() . This function is called whenever handleRequest() returns false, or if there is a WebSocket upgrade attempt and either there are no connections to newWebSocketConnection() or there are no matching WebSocket verifiers. The request and responder parameters are the same as handleRequest() was called with.

See also

handleRequest() addWebSocketUpgradeVerifier()

serverPorts()
Return type:

.list of quint16

Returns the list of ports this instance of QAbstractHttpServer is listening to.

This function has the same guarantee as QObject::children, the latest server added is the last entry in the vector.

See also

servers()

servers()
Return type:

.list of QTcpServer

Returns the TCP servers of this HTTP server.

See also

serverPorts()

setHttp2Configuration(configuration)
Parameters:

configurationQHttp2Configuration

Sets server’s HTTP/2 configuration parameters.

The next HTTP/2 connection will use the given configuration.