- class QAbstractHttpServer¶
API to subclass to implement an HTTP server. More…
Inherited by:
QHttpServer
Synopsis¶
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
QHttpServer
for a highler level API to implement an HTTP server.Creates an instance of
QAbstractHttpServer
with the parentparent
.- bind(server)¶
- Parameters:
server –
QLocalServer
- 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 ofserver
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. Ifserver
is not listening, nothing will happen andfalse
will be returned.If the
server
is nullptr false is returned.If successful the
server
will be parented to this HTTP server andtrue
is returned.See also
listen()
- bind(server)
- Parameters:
server –
QTcpServer
- 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 TCPserver
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. Ifserver
is not listening, nothing will happen andfalse
will be returned.If successful the
server
will be parented to this HTTP server andtrue
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:
request –
QHttpServerRequest
responder –
QHttpServerResponder
- Return type:
bool
Override this function to handle each incoming
request
, by examining therequest
and sending the appropriate response back toresponder
. Returntrue
if therequest
was handled successfully. If this method returnsfalse
,missingHandler()
will be called afterwards.This function must move out of
responder
before 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 –
QHttpServerRequest
responder –
QHttpServerResponder
Override this function to handle each incoming
request
that 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. Therequest
andresponder
parameters 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
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()¶
- 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