1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QHttpServerHttp2ProtocolHandler_H
5#define QHttpServerHttp2ProtocolHandler_H
6
7#include <QtHttpServer/qthttpserverglobal.h>
8#include <QtHttpServer/qhttpserverrequest.h>
9#include <QtHttpServer/private/qhttpserverstream_p.h>
10#include <QtNetwork/private/hpack_p.h>
11#include <QtCore/qbytearray.h>
12#include <QtCore/qqueue.h>
13
14//
15// W A R N I N G
16// -------------
17//
18// This file is not part of the Qt API. It exists for the convenience
19// of QHttpServer. This header file may change from version to
20// version without notice, or even be removed.
21//
22// We mean it.
23
24QT_REQUIRE_CONFIG(http);
25QT_REQUIRE_CONFIG(ssl);
26
27QT_BEGIN_NAMESPACE
28
29class QTcpSocket;
30class QAbstractHttpServer;
31class QHttp2Connection;
32class QHttp2Stream;
33
34struct QHttpServerHttp2Queue
35{
36 QQueue<QByteArray> data;
37 HPack::HttpHeader trailers;
38 bool allEnqueued = false;
39};
40
41class QHttpServerHttp2ProtocolHandler : public QHttpServerStream
42{
43 Q_OBJECT
44
45 friend class QAbstractHttpServerPrivate;
46
47private:
48 QHttpServerHttp2ProtocolHandler(QAbstractHttpServer *server, QIODevice *socket);
49
50 void responderDestroyed() final;
51 void startHandlingRequest() final;
52 void socketDisconnected() final;
53
54 void write(const QByteArray &body, const QHttpHeaders &headers,
55 QHttpServerResponder::StatusCode status, quint32 streamId) final;
56 void write(QHttpServerResponder::StatusCode status, quint32 streamId) final;
57 void write(QIODevice *data, const QHttpHeaders &headers,
58 QHttpServerResponder::StatusCode status, quint32 streamId) final;
59 void writeBeginChunked(const QHttpHeaders &headers,
60 QHttpServerResponder::StatusCode status,
61 quint32 streamId) final;
62 void writeChunk(const QByteArray &body, quint32 streamId) final;
63 void writeEndChunked(const QByteArray &data,
64 const QHttpHeaders &trailers,
65 quint32 streamId) final;
66
67 void writeHeadersAndStatus(const QHttpHeaders &headers,
68 QHttpServerResponder::StatusCode status,
69 bool endStream,
70 quint32 streamId);
71
72private slots:
73 void onStreamCreated(QHttp2Stream *stream);
74 void onStreamClosed(quint32 streamId);
75 void onStreamHalfClosed(quint32 streamId);
76 void sendToStream(quint32 streamId);
77
78private:
79 QHttp2Stream * getStream(quint32 streamId) const;
80 void enqueueChunk(const QByteArray &body, bool allEnqueued, const QHttpHeaders &trailers,
81 quint32 streamId);
82
83 QAbstractHttpServer *m_server;
84 QIODevice *m_socket;
85 QTcpSocket *m_tcpSocket;
86 QHttpServerRequest m_request;
87 QHttp2Connection *m_connection;
88 QHash<quint32, QList<QMetaObject::Connection>> m_streamConnections;
89 QHash<quint32, QHttpServerHttp2Queue> m_streamQueue;
90 qint32 m_responderCounter = 0;
91};
92
93QT_END_NAMESPACE
94
95#endif // QHttpServerHttp2ProtocolHandler_H
96

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qthttpserver/src/httpserver/qhttpserverhttp2protocolhandler_p.h