QAbstractHttpServer Class
HTTP 서버를 구현하기 위해 상속해야 할 API. 더 보기...
| 헤더: | #include <QAbstractHttpServer> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS HttpServer) target_link_libraries(mytarget PRIVATE Qt6::HttpServer) |
| qmake: | QT += httpserver |
| 다음부터: | Qt 6.4 |
| 상속받은 항목: | QObject |
| 상속받는 클래스: |
공개 함수
| QAbstractHttpServer(QObject *parent = nullptr) | |
| virtual | ~QAbstractHttpServer() override |
(since 6.8) void | addWebSocketUpgradeVerifier(const QObject *context, Handler &&func) |
| bool | bind(QLocalServer *server) |
| bool | bind(QTcpServer *server) |
(since 6.9) QHttpServerConfiguration | configuration() const |
| bool | hasPendingWebSocketConnections() const |
(since 6.8) QHttp2Configuration | http2Configuration() const |
| QList<QLocalServer *> | localServers() const |
| std::unique_ptr<QWebSocket> | nextPendingWebSocketConnection() |
| QList<quint16> | serverPorts() const |
| QList<QTcpServer *> | servers() const |
(since 6.9) void | setConfiguration(const QHttpServerConfiguration &config) |
(since 6.8) void | setHttp2Configuration(const QHttp2Configuration &configuration) |
신호
| void | newWebSocketConnection() |
보호된 함수
| virtual bool | handleRequest(const QHttpServerRequest &request, QHttpServerResponder &responder) = 0 |
| virtual void | missingHandler(const QHttpServerRequest &request, QHttpServerResponder &responder) = 0 |
상세 설명
이 클래스를 서브클래스로 상속하고, ` handleRequest()` 및 ` missingHandler()`을 오버라이드하여 HTTP 서버를 생성하십시오. ` bind()`을 사용하여 서버로 들어오는 모든 연결을 수신 대기하도록 시작하십시오.
이것은 저수준 API입니다. HTTP 서버를 구현하기 위한 상위 수준의 API에 대해서는 QHttpServer 를 참조하십시오.
멤버 함수 문서
[explicit] QAbstractHttpServer::QAbstractHttpServer(QObject *parent = nullptr)
parent 를 부모 클래스로 하여 QAbstractHttpServer의 인스턴스를 생성합니다.
[override virtual noexcept] QAbstractHttpServer::~QAbstractHttpServer()
QAbstractHttpServer 의 인스턴스를 삭제합니다.
[since 6.8] template <typename Handler> void QAbstractHttpServer::addWebSocketUpgradeVerifier(const QObject *context, Handler &&func)
수신되는 WebSocket 업그레이드 요청을 검증하는 콜백 함수 func 를 추가합니다. 이 함수는 제공된 context 객체를 통해 호출됩니다. 등록된 콜백 중 하나 이상이 Accept 를 반환하고, 이전 콜백 중 어느 것도 Deny 를 반환하지 않은 경우 업그레이드가 성공한 것으로 간주됩니다. 등록된 콜백이 없거나 모든 콜백이 PassToNext 를 반환하는 경우, missingHandler() 함수가 호출됩니다. 콜백은 등록된 순서대로 실행되며, 콜백 자체는 이 함수를 호출할 수 없습니다.
참고: ` func `는 ` QHttpServerWebSocketUpgradeResponse (*)(const QHttpServerRequest &)` 시그니처를 구현해야 합니다.
server.addWebSocketUpgradeVerifier(
&server, [](const QHttpServerRequest &request) {
if (request.url().path() == "/allowed"_L1)
return QHttpServerWebSocketUpgradeResponse::accept();
else
return QHttpServerWebSocketUpgradeResponse::passToNext();
});이 함수는 Qt 6.8에서 도입되었습니다.
QHttpServerRequest, QHttpServerWebSocketUpgradeResponse, hasPendingWebSocketConnections(), nextPendingWebSocketConnection(), newWebSocketConnection() 및 missingHandler()도 참조하십시오 .
bool QAbstractHttpServer::bind(QLocalServer *server)
전송이 이루어지는 지정된 QLocalServer server 을 HTTP 서버에 바인딩합니다. 여러 연결을 처리하기 위해 server 의 서로 다른 인스턴스를 사용하여 이 함수를 여러 번 호출할 수 있습니다.
이 함수를 호출한 후에는 모든 새로운 연결이 HTTP 서버에 의해 처리되고 전달됩니다.
이 함수를 호출하기 전에 server 에서 QLocalServer::listen()를 호출하는 것은 사용자의 책임입니다. server 가 수신 대기 중이 아닌 경우 아무 일도 일어나지 않으며 false 가 반환됩니다.
server 가 nullptr인 경우 false가 반환됩니다.
성공하면 server 는 이 HTTP 서버의 자식 서버가 되며 true 가 반환됩니다.
QLocalServer 및 QLocalServer::listen()도 참조하십시오 .
bool QAbstractHttpServer::bind(QTcpServer *server)
전송이 이루어지는 지정된 TCP server 을 HTTP 서버에 바인딩합니다. 이 함수를 서로 다른 TCP server 인스턴스와 함께 여러 번 호출하여, 예를 들어 SSL 연결과 암호화되지 않은 연결 등 여러 연결 및 포트를 처리할 수 있습니다.
이 함수를 호출하면, 이후 발생하는 모든 새로운 연결은 HTTP 서버에 의해 처리되고 전달됩니다.
이 함수를 호출하기 전에 server 에 대해 QTcpServer::listen()를 호출하는 것은 사용자의 책임입니다. server 가 수신 대기 중이 아닌 경우 아무 일도 일어나지 않으며 false 가 반환됩니다.
성공하면 server 가 이 HTTP 서버의 자식 노드로 등록되며 true 가 반환됩니다.
HTTP 2를 사용하려면, { QSslConfiguration::ALPNProtocolHTTP2 } 인수를 사용하여 QSslConfiguration::setAllowedNextProtocols()가 호출된 QSslServer 에 바인딩하십시오.
QTcpServer, QTcpServer::listen() 및 QSslConfiguration::setAllowedNextProtocols()도 참조하십시오 .
[since 6.9] QHttpServerConfiguration QAbstractHttpServer::configuration() const
이 서버의 일반 구성 매개변수를 반환합니다.
이 함수는 Qt 6.9에서 도입되었습니다.
setConfiguration()도 참조하십시오 .
[pure virtual protected] bool QAbstractHttpServer::handleRequest(const QHttpServerRequest &request, QHttpServerResponder &responder)
이 함수를 재정의하여 수신되는 각 request 요청을 처리하고, request 를 확인한 후 responder 로 적절한 응답을 반환하십시오. request 처리가 성공적으로 완료된 경우 true 를 반환하십시오. 이 메서드가 false 를 반환하면, 그 후 missingHandler()가 호출됩니다.
bool QAbstractHttpServer::hasPendingWebSocketConnections() const
서버에 대기 중인 WebSocket 연결이 있으면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.
newWebSocketConnection(), nextPendingWebSocketConnection(), addWebSocketUpgradeVerifier()도 참조하십시오 .
[since 6.8] QHttp2Configuration QAbstractHttpServer::http2Configuration() const
서버의 HTTP/2 구성 매개변수를 반환합니다.
이 함수는 Qt 6.8에서 도입되었습니다.
setHttp2Configuration()도 참조하십시오 .
QList<QLocalServer *> QAbstractHttpServer::localServers() const
이 HTTP 서버의 로컬 서버를 반환합니다.
serverPorts()도 참조하십시오 .
[pure virtual protected] void QAbstractHttpServer::missingHandler(const QHttpServerRequest &request, QHttpServerResponder &responder)
handleRequest()에서 처리되지 않은 각 수신 request 를 처리하려면 이 함수를 재정의하십시오. 이 함수는 handleRequest()가 false 를 반환할 때, 또는 WebSocket 업그레이드 시도가 발생했을 때 newWebSocketConnection()에 연결된 연결이 없거나 일치하는 WebSocket 검증기가 없을 때 호출됩니다. request 및 responder 매개변수는 handleRequest()가 호출될 때 전달된 매개변수와 동일합니다.
handleRequest() 및 addWebSocketUpgradeVerifier()도 참조하십시오 .
[signal] void QAbstractHttpServer::newWebSocketConnection()
이 신호는 새로운 WebSocket 연결이 가능해질 때마다 전송됩니다.
hasPendingWebSocketConnections(), nextPendingWebSocketConnection(), addWebSocketUpgradeVerifier()도 참조하십시오 .
std::unique_ptr<QWebSocket> QAbstractHttpServer::nextPendingWebSocketConnection()
대기 중인 다음 연결을 연결된 ` QWebSocket ` 객체로 반환합니다. 대기 중인 연결이 없는 상태에서 이 함수가 호출되면 ` nullptr `가 반환됩니다.
참고: 반환된 QWebSocket 객체는 다른 스레드에서 사용할 수 없습니다.
참조: newWebSocketConnection(), hasPendingWebSocketConnections(), addWebSocketUpgradeVerifier().
QList<quint16> QAbstractHttpServer::serverPorts() const
QAbstractHttpServer 의 이 인스턴스가 수신 대기 중인 포트 목록을 반환합니다.
이 함수는 ` QObject::children`와 동일한 동작을 보장하며, 가장 최근에 추가된 서버가 벡터의 마지막 항목이 됩니다.
servers()도 참조하십시오 .
QList<QTcpServer *> QAbstractHttpServer::servers() const
이 HTTP 서버가 연결을 처리할 TCP 및 SSL 서버를 반환합니다.
serverPorts()도 참조하십시오 .
[since 6.9] void QAbstractHttpServer::setConfiguration(const QHttpServerConfiguration &config)
이 서버의 일반 구성 매개변수를 config 로 설정합니다.
참고: 새로운구성은 이미 설정된 연결과 향후 모든 연결에 모두 적용됩니다.
이 함수는 Qt 6.9에서 도입되었습니다.
configuration()도 참조하십시오 .
[since 6.8] void QAbstractHttpServer::setHttp2Configuration(const QHttp2Configuration &configuration)
서버의 HTTP/2 구성 매개변수를 설정합니다.
다음 HTTP/2 연결에서는 지정된 ` configuration`를 사용합니다.
이 함수는 Qt 6.8에서 도입되었습니다.
http2Configuration()도 참조하십시오 .
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.