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 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QHttp2Stream; |
24 | |
25 | class QHttpServerRequestPrivate |
26 | { |
27 | public: |
28 | QHttpServerRequestPrivate(const QHostAddress &remoteAddress, quint16 remotePort, |
29 | const QHostAddress &localAddress, quint16 localPort); |
30 | #if QT_CONFIG(ssl) |
31 | QHttpServerRequestPrivate(const QHostAddress &remoteAddress, quint16 remotePort, |
32 | const QHostAddress &localAddress, quint16 localPort, |
33 | const QSslConfiguration &sslConfiguration); |
34 | #endif |
35 | |
36 | quint16 port = 0; |
37 | |
38 | enum class State { |
39 | NothingDone, |
40 | ReadingRequestLine, |
41 | , |
42 | ExpectContinue, |
43 | ReadingData, |
44 | AllDone, |
45 | } state = State::NothingDone; |
46 | |
47 | QUrl url; |
48 | QHttpServerRequest::Method method; |
49 | QHttpHeaderParser parser; |
50 | |
51 | bool parseRequestLine(QByteArrayView line); |
52 | qsizetype readRequestLine(QIODevice *socket); |
53 | qsizetype (QIODevice *socket); |
54 | qsizetype sendContinue(QIODevice *socket); |
55 | qsizetype readBodyFast(QIODevice *socket); |
56 | qsizetype readRequestBodyRaw(QIODevice *socket, qsizetype size); |
57 | qsizetype readRequestBodyChunked(QIODevice *socket); |
58 | qsizetype getChunkSize(QIODevice *socket, qsizetype *chunkSize); |
59 | |
60 | bool parse(QIODevice *socket); |
61 | #if QT_CONFIG(http) |
62 | bool parse(QHttp2Stream *socket); |
63 | #endif |
64 | void clear(); |
65 | |
66 | qint64 contentLength() const; |
67 | QByteArray (const QByteArray &name) const |
68 | { return parser.combinedHeaderValue(name); } |
69 | |
70 | QHostAddress remoteAddress; |
71 | quint16 remotePort; |
72 | QHostAddress localAddress; |
73 | quint16 localPort; |
74 | #if QT_CONFIG(ssl) |
75 | QSslConfiguration sslConfiguration; |
76 | #endif |
77 | bool handling{false}; |
78 | qsizetype bodyLength; |
79 | qsizetype contentRead; |
80 | bool chunkedTransferEncoding; |
81 | bool lastChunkRead; |
82 | qsizetype currentChunkRead; |
83 | qsizetype currentChunkSize; |
84 | bool upgrade; |
85 | |
86 | QByteArray fragment; |
87 | QByteDataBuffer bodyBuffer; |
88 | QByteArray body; |
89 | }; |
90 | |
91 | QT_END_NAMESPACE |
92 | |
93 | #endif // QHTTPSERVERREQUEST_P_H |
94 | |