1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QHttpServerHttp1ProtocolHandler_H
5#define QHttpServerHttp1ProtocolHandler_H
6
7#include <QtHttpServer/qthttpserverglobal.h>
8#include <QtHttpServer/qhttpserverrequest.h>
9#include <QtHttpServer/private/qhttpserverstream_p.h>
10
11//
12// W A R N I N G
13// -------------
14//
15// This file is not part of the Qt API. It exists for the convenience
16// of QHttpServer. This header file may change from version to
17// version without notice, or even be removed.
18//
19// We mean it.
20
21QT_BEGIN_NAMESPACE
22
23class QTcpSocket;
24class QAbstractHttpServer;
25#if QT_CONFIG(localserver)
26class QLocalSocket;
27#endif
28
29class QHttpServerHttp1ProtocolHandler : public QHttpServerStream
30{
31 Q_OBJECT
32
33 friend class QAbstractHttpServerPrivate;
34 friend class QHttpServerResponder;
35
36private:
37 QHttpServerHttp1ProtocolHandler(QAbstractHttpServer *server, QIODevice *socket);
38
39 void responderDestroyed() final;
40 void startHandlingRequest() final;
41 void socketDisconnected() final;
42
43 void handleReadyRead();
44
45 void write(const QByteArray &body, const QHttpHeaders &headers,
46 QHttpServerResponder::StatusCode status, quint32 streamId) final;
47 void write(QHttpServerResponder::StatusCode status, quint32 streamId) final;
48 void write(QIODevice *data, const QHttpHeaders &headers,
49 QHttpServerResponder::StatusCode status, quint32 streamId) final;
50 void writeBeginChunked(const QHttpHeaders &headers,
51 QHttpServerResponder::StatusCode status,
52 quint32 streamId) final;
53 void writeChunk(const QByteArray &body, quint32 streamId) final;
54 void writeEndChunked(const QByteArray &data,
55 const QHttpHeaders &trailers,
56 quint32 streamId) final;
57
58 void writeStatusAndHeaders(QHttpServerResponder::StatusCode status,
59 const QHttpHeaders &headers);
60 void writeHeader(const QByteArray &key, const QByteArray &value);
61 void write(const QByteArray &data);
62 void write(const char *body, qint64 size);
63
64 QAbstractHttpServer *server;
65 QIODevice *socket;
66 QTcpSocket *tcpSocket;
67#if QT_CONFIG(localserver)
68 QLocalSocket *localSocket;
69#endif
70
71 enum class TransferState {
72 Ready,
73 HeadersSent,
74 ChunkedTransferBegun
75 } state = TransferState::Ready;
76
77 QHttpServerRequest request;
78
79 // To avoid destroying the object when socket object is destroyed while
80 // a request is still being handled.
81 bool handlingRequest = false;
82 bool protocolChanged = false;
83};
84
85QT_END_NAMESPACE
86
87#endif // QHttpServerHttp1ProtocolHandler_H
88

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

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