PySide6.QtHttpServer.QAbstractHttpServer¶
- class QAbstractHttpServer¶
API to subclass to implement an HTTP server. More…
Inherited by:
QHttpServerSynopsis¶
Methods¶
def
__init__()def
bind()def
localServers()def
serverPorts()def
servers()
Virtual methods¶
def
handleRequest()def
missingHandler()
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()andmissingHandler()to create an HTTP server. Usebind()to start listening to all the incoming connections to a server.This is a low level API, see
QHttpServerfor a highler level API to implement an HTTP server.Creates an instance of
QAbstractHttpServerwith the parentparent.- bind(server)¶
- Parameters:
server –
QLocalServer- Return type:
bool
Bind the HTTP server to given QLocalServer
serverover which the transmission happens. It is possible to call this function multiple times with different instances ofserverto 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
serverbefore calling this function. Ifserveris not listening, nothing will happen andfalsewill be returned.If the
serveris nullptr false is returned.If successful the
serverwill be parented to this HTTP server andtrueis returned.See also
listen()- bind(server)
- Parameters:
server –
QTcpServer- Return type:
bool
Bind the HTTP server to given TCP
serverover which the transmission happens. It is possible to call this function multiple times with different instances of TCPserverto 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
serverbefore calling this function. Ifserveris not listening, nothing will happen andfalsewill be returned.If successful the
serverwill be parented to this HTTP server andtrueis 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:
request –
QHttpServerRequestresponder –
QHttpServerResponder
- Return type:
bool
Override this function to handle each incoming
request, by examining therequestand sending the appropriate response back toresponder. Returntrueif therequestwas handled successfully. If this method returnsfalse,missingHandler()will be called afterwards.This function must move out of
responderbefore returningtrue.- http2Configuration()¶
- Return type:
Returns server’s HTTP/2 configuration parameters.
See also
- localServers()¶
- Return type:
.list of QLocalServer
Returns the local servers of this HTTP server.
See also
- abstract missingHandler(request, responder)¶
- Parameters:
request –
QHttpServerRequestresponder –
QHttpServerResponder
Override this function to handle each incoming
requestthat was not handled byhandleRequest(). This function is called wheneverhandleRequest()returnsfalse, or if there is a WebSocket upgrade attempt and either there are no connections tonewWebSocketConnection()or there are no matching WebSocket verifiers. Therequestandresponderparameters are the same ashandleRequest()was called with.See also
handleRequest()addWebSocketUpgradeVerifier()- serverPorts()¶
- Return type:
.list of quint16
Returns the list of ports this instance of
QAbstractHttpServeris 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()¶
- Return type:
.list of QTcpServer
Returns the TCP servers of this HTTP server.
See also
- setHttp2Configuration(configuration)¶
- Parameters:
configuration –
QHttp2Configuration
Sets server’s HTTP/2 configuration parameters.
The next HTTP/2 connection will use the given
configuration.See also