Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qhttpnetworkconnectionchannel_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QHTTPNETWORKCONNECTIONCHANNEL_H
6#define QHTTPNETWORKCONNECTIONCHANNEL_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include <QtNetwork/qnetworkrequest.h>
21#include <QtNetwork/qnetworkreply.h>
22#include <QtNetwork/qabstractsocket.h>
23
24#include <private/qobject_p.h>
25#include <qauthenticator.h>
26#include <qnetworkproxy.h>
27#include <qbuffer.h>
28
29#include <private/qhttpnetworkheader_p.h>
30#include <private/qhttpnetworkrequest_p.h>
31#include <private/qhttpnetworkreply_p.h>
32
33#include <private/qhttpnetworkconnection_p.h>
34#include <private/qabstractprotocolhandler_p.h>
35
36#ifndef QT_NO_SSL
37# include <QtNetwork/qsslsocket.h>
38# include <QtNetwork/qsslerror.h>
39# include <QtNetwork/qsslconfiguration.h>
40#else
41# include <QtNetwork/qtcpsocket.h>
42#endif
43#if QT_CONFIG(localserver)
44# include <QtNetwork/qlocalsocket.h>
45#endif
46
47
48#include <QtCore/qpointer.h>
49
50#include <memory>
51#include <optional>
52#include <utility>
53
55
56QT_BEGIN_NAMESPACE
57
58class QHttpNetworkRequest;
59class QHttpNetworkReply;
60class QByteArray;
62
63#ifndef HttpMessagePair
64typedef std::pair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair;
65#endif
66
69public:
70 // TODO: Refactor this to add an EncryptingState (and remove pendingEncrypt).
71 // Also add an Unconnected state so IdleState does not have double meaning.
73 IdleState = 0, // ready to send request
74 ConnectingState = 1, // connecting to host
75 WritingState = 2, // writing the data
76 WaitingState = 4, // waiting for reply
77 ReadingState = 8, // reading the reply
80 };
82 bool ssl;
86 bool needInvokeReadyRead = false;
89 QHttpNetworkRequest request; // current request, only used for HTTP
90 QHttpNetworkReply *reply; // current reply for this request, only used for HTTP
94 int lastStatus; // last status received on this channel
95 bool pendingEncrypt; // for https (send after encrypted)
96 int reconnectAttempts; // maximum 2 reconnection attempts
103 bool switchedToHttp2 = false;
105#ifndef QT_NO_SSL
108 std::optional<QSslConfiguration> sslConfiguration;
109 void ignoreSslErrors();
110 void ignoreSslErrors(const QList<QSslError> &errors);
111 void setSslConfiguration(const QSslConfiguration &config);
112 void requeueHttp2Requests(); // when we wanted HTTP/2 but got HTTP/1.1
113#endif
114 // to emit the signal for all in-flight replies:
115 void emitFinishedWithError(QNetworkReply::NetworkError error, const char *message);
116
117 // HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining
119 PipeliningSupportUnknown, // default for a new connection
120 PipeliningProbablySupported, // after having received a server response that indicates support
121 PipeliningNotSupported // currently not used
122 };
125 QByteArray pipeline; // temporary buffer that gets sent to socket in pipelineFlush
126 void pipelineInto(HttpMessagePair &pair);
127 void pipelineFlush();
130
132
134
135 void setConnection(QHttpNetworkConnection *c);
137
138#ifndef QT_NO_NETWORKPROXY
140 void setProxy(const QNetworkProxy &networkProxy);
141#endif
142
143 void init();
144 void close();
145 void abort();
146
147 void sendRequest();
148 void sendRequestDelayed();
149
150 bool ensureConnection();
151
152 void allDone(); // reply header + body have been read
153 void handleStatus(); // called from allDone()
154
155 bool resetUploadData(); // return true if resetting worked or there is no upload data
156
157 void handleUnexpectedEOF();
160
162
163 bool isSocketBusy() const;
164 bool isSocketWriting() const;
165 bool isSocketWaiting() const;
166 bool isSocketReading() const;
167
168 protected slots:
169 void _q_receiveReply();
170 void _q_bytesWritten(qint64 bytes); // proceed sending
171 void _q_readyRead(); // pending data to read
172 void _q_disconnected(); // disconnected from host
173 void _q_connected_abstract_socket(QAbstractSocket *socket);
174#if QT_CONFIG(localserver)
176#endif
177 void _q_connected(); // start sending request
178 void _q_error(QAbstractSocket::SocketError); // error from socket
179#ifndef QT_NO_NETWORKPROXY
180 void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy
181#endif
182
184
185#ifndef QT_NO_SSL
186 void _q_encrypted(); // start sending request (https)
187 void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket
188 void _q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*); // tls-psk auth necessary
189 void _q_encryptedBytesWritten(qint64 bytes); // proceed sending
190#endif
191
192 friend class QHttpProtocolHandler;
193};
194
195QT_END_NAMESPACE
196
197#endif
std::unique_ptr< QAbstractProtocolHandler > protocolHandler
void setProxy(const QNetworkProxy &networkProxy)
void _q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *)
QAbstractSocket::NetworkLayerProtocol networkLayerPreference
void emitFinishedWithError(QNetworkReply::NetworkError error, const char *message)
QPointer< QHttpNetworkConnection > connection
QMultiMap< int, HttpMessagePair > h2RequestsToSend
std::optional< QSslConfiguration > sslConfiguration
void _q_sslErrors(const QList< QSslError > &errors)
void setConnection(QHttpNetworkConnection *c)
void _q_connected_abstract_socket(QAbstractSocket *socket)
void ignoreSslErrors(const QList< QSslError > &errors)
void _q_error(QAbstractSocket::SocketError)
void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth)
QHttp2ProtocolHandler * h2ProtocolHandler() const noexcept
qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const
bool shouldEmitChannelError(QIODevice *socket)
void createAuthorization(QIODevice *socket, QHttpNetworkRequest &request)
void emitReplyError(QIODevice *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode)
QUrl parseRedirectResponse(QIODevice *socket, QHttpNetworkReply *reply)
QHttpNetworkRequest predictNextRequest() const
void prepareRequest(HttpMessagePair &request)
NetworkLayerPreferenceState networkLayerState
void copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy)
void networkLayerDetected(QAbstractSocket::NetworkLayerProtocol protocol)
void requeueRequest(const HttpMessagePair &pair)
void removeReply(QHttpNetworkReply *reply)
void _q_hostLookupFinished(const QHostInfo &info)
QHttpNetworkReply * predictNextRequestsReply() const
void updateChannel(int i, const HttpMessagePair &messagePair)
bool handleAuthenticateChallenge(QIODevice *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend)
QHttpNetworkReply * queueRequest(const QHttpNetworkRequest &request)
void readMoreLater(QHttpNetworkReply *reply)
int indexOf(QIODevice *socket) const
qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const
static ParseRedirectResult parseRedirectResponse(QHttpNetworkReply *reply)
Definition qspan.h:320
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:177
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(http)
static QStringView removeZoneId(QStringView ipv6HostAddress)
static QByteArray makeAcceptLanguage()
static int getPreferredActiveChannelCount(QHttpNetworkConnection::ConnectionType type, int defaultValue)
std::pair< QHttpNetworkRequest, QHttpNetworkReply * > HttpMessagePair