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 bool isPendingReconnect() const noexcept;
107 void requeueHttp2Requests(); // when we wanted HTTP/2 but got HTTP/1.1, or are reconnecting
108#ifndef QT_NO_SSL
111 std::optional<QSslConfiguration> sslConfiguration;
112 void ignoreSslErrors();
113 void ignoreSslErrors(const QList<QSslError> &errors);
114 void setSslConfiguration(const QSslConfiguration &config);
115#endif
116 // to emit the signal for all in-flight replies:
117 void emitFinishedWithError(QNetworkReply::NetworkError error, const char *message);
118 void emitFinishedWithError(QNetworkReply::NetworkError error, const QString &message);
119
120 // HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining
122 PipeliningSupportUnknown, // default for a new connection
123 PipeliningProbablySupported, // after having received a server response that indicates support
124 PipeliningNotSupported // currently not used
125 };
128 QByteArray pipeline; // temporary buffer that gets sent to socket in pipelineFlush
129 void pipelineInto(HttpMessagePair &pair);
130 void pipelineFlush();
133
135
137
138 void setConnection(QHttpNetworkConnection *c);
140
141#ifndef QT_NO_NETWORKPROXY
143 void setProxy(const QNetworkProxy &networkProxy);
144#endif
145
146 void init();
147 void close();
148 void abort();
149
150 void sendRequest();
151 void sendRequestDelayed();
152
153 bool ensureConnection();
154
155 void allDone(); // reply header + body have been read
156 void handleStatus(); // called from allDone()
157
158 bool resetUploadData(); // return true if resetting worked or there is no upload data
159
160 void handleUnexpectedEOF();
163
165
166 bool isSocketBusy() const;
167 bool isSocketWriting() const;
168 bool isSocketWaiting() const;
169 bool isSocketReading() const;
170
171 protected slots:
172 void _q_receiveReply();
173 void _q_bytesWritten(qint64 bytes); // proceed sending
174 void _q_readyRead(); // pending data to read
175 void _q_disconnected(); // disconnected from host
176 void _q_connected_abstract_socket(QAbstractSocket *socket);
177#if QT_CONFIG(localserver)
179#endif
180 void _q_connected(); // start sending request
181 void _q_error(QAbstractSocket::SocketError); // error from socket
182#ifndef QT_NO_NETWORKPROXY
183 void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy
184#endif
185
187
188#ifndef QT_NO_SSL
189 void _q_encrypted(); // start sending request (https)
190 void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket
191 void _q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*); // tls-psk auth necessary
192 void _q_encryptedBytesWritten(qint64 bytes); // proceed sending
193#endif
194
195 friend class QHttpProtocolHandler;
196};
197
198QT_END_NAMESPACE
199
200#endif
std::unique_ptr< QAbstractProtocolHandler > protocolHandler
void emitFinishedWithError(QNetworkReply::NetworkError error, const QString &message)
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
QString errorDetail(QNetworkReply::NetworkError errorCode, QIODevice *socket, const QString &extraDetail=QString())
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)
QHttpNetworkConnectionPrivate(quint16 connectionCount, const QString &hostName, quint16 port, bool encrypt, bool isLocalSocket, QHttpNetworkConnection::ConnectionType type)
void emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator *auth)
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)
bool fillPipeline(QList< HttpMessagePair > &queue, QHttpNetworkConnectionChannel &channel)
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