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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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