1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QHTTPSERVERREQUEST_P_H
5#define QHTTPSERVERREQUEST_P_H
6
7#include <QtHttpServer/qhttpserverrequest.h>
8#include <QtNetwork/private/qhttpheaderparser_p.h>
9#include <QtCore/private/qbytedata_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 QHttpServerRequestPrivate
24{
25public:
26 QHttpServerRequestPrivate(const QHostAddress &remoteAddress, quint16 remotePort,
27 const QHostAddress &localAddress, quint16 localPort);
28
29 quint16 port = 0;
30
31 enum class State {
32 NothingDone,
33 ReadingRequestLine,
34 ReadingHeader,
35 ExpectContinue,
36 ReadingData,
37 AllDone,
38 } state = State::NothingDone;
39
40 QUrl url;
41 QHttpServerRequest::Method method;
42 QHttpHeaderParser parser;
43
44 bool parseRequestLine(QByteArrayView line);
45 qsizetype readRequestLine(QAbstractSocket *socket);
46 qsizetype readHeader(QAbstractSocket *socket);
47 qsizetype sendContinue(QAbstractSocket *socket);
48 qsizetype readBodyFast(QAbstractSocket *socket);
49 qsizetype readRequestBodyRaw(QAbstractSocket *socket, qsizetype size);
50 qsizetype readRequestBodyChunked(QAbstractSocket *socket);
51 qsizetype getChunkSize(QAbstractSocket *socket, qsizetype *chunkSize);
52
53 bool parse(QAbstractSocket *socket);
54
55 void clear();
56
57 qint64 contentLength() const;
58 QByteArray headerField(const QByteArray &name) const
59 { return parser.combinedHeaderValue(name); }
60
61 QHostAddress remoteAddress;
62 quint16 remotePort;
63 QHostAddress localAddress;
64 quint16 localPort;
65 bool handling{false};
66 qsizetype bodyLength;
67 qsizetype contentRead;
68 bool chunkedTransferEncoding;
69 bool lastChunkRead;
70 qsizetype currentChunkRead;
71 qsizetype currentChunkSize;
72 bool upgrade;
73
74 QByteArray fragment;
75 QByteDataBuffer bodyBuffer;
76 QByteArray body;
77};
78
79QT_END_NAMESPACE
80
81#endif // QHTTPSERVERREQUEST_P_H
82

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