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;
61
62#ifndef HttpMessagePair
63typedef std::pair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair;
64#endif
65
68public:
69 // TODO: Refactor this to add an EncryptingState (and remove pendingEncrypt).
70 // Also add an Unconnected state so IdleState does not have double meaning.
72 IdleState = 0, // ready to send request
73 ConnectingState = 1, // connecting to host
74 WritingState = 2, // writing the data
75 WaitingState = 4, // waiting for reply
76 ReadingState = 8, // reading the reply
79 };
81 bool ssl;
85 bool needInvokeReadyRead = false;
88 QHttpNetworkRequest request; // current request, only used for HTTP
89 QHttpNetworkReply *reply; // current reply for this request, only used for HTTP
93 int lastStatus; // last status received on this channel
94 bool pendingEncrypt; // for https (send after encrypted)
95 int reconnectAttempts; // maximum 2 reconnection attempts
102 bool switchedToHttp2 = false;
103#ifndef QT_NO_SSL
106 std::optional<QSslConfiguration> sslConfiguration;
107 void ignoreSslErrors();
108 void ignoreSslErrors(const QList<QSslError> &errors);
109 void setSslConfiguration(const QSslConfiguration &config);
110 void requeueHttp2Requests(); // when we wanted HTTP/2 but got HTTP/1.1
111#endif
112 // to emit the signal for all in-flight replies:
113 void emitFinishedWithError(QNetworkReply::NetworkError error, const char *message);
114
115 // HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining
117 PipeliningSupportUnknown, // default for a new connection
118 PipeliningProbablySupported, // after having received a server response that indicates support
119 PipeliningNotSupported // currently not used
120 };
123 QByteArray pipeline; // temporary buffer that gets sent to socket in pipelineFlush
124 void pipelineInto(HttpMessagePair &pair);
125 void pipelineFlush();
128
130
132
133 void setConnection(QHttpNetworkConnection *c);
135
136#ifndef QT_NO_NETWORKPROXY
138 void setProxy(const QNetworkProxy &networkProxy);
139#endif
140
141 void init();
142 void close();
143 void abort();
144
145 void sendRequest();
146 void sendRequestDelayed();
147
148 bool ensureConnection();
149
150 void allDone(); // reply header + body have been read
151 void handleStatus(); // called from allDone()
152
153 bool resetUploadData(); // return true if resetting worked or there is no upload data
154
155 void handleUnexpectedEOF();
158
160
161 bool isSocketBusy() const;
162 bool isSocketWriting() const;
163 bool isSocketWaiting() const;
164 bool isSocketReading() const;
165
166 protected slots:
167 void _q_receiveReply();
168 void _q_bytesWritten(qint64 bytes); // proceed sending
169 void _q_readyRead(); // pending data to read
170 void _q_disconnected(); // disconnected from host
171 void _q_connected_abstract_socket(QAbstractSocket *socket);
172#if QT_CONFIG(localserver)
174#endif
175 void _q_connected(); // start sending request
176 void _q_error(QAbstractSocket::SocketError); // error from socket
177#ifndef QT_NO_NETWORKPROXY
178 void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy
179#endif
180
182
183#ifndef QT_NO_SSL
184 void _q_encrypted(); // start sending request (https)
185 void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket
186 void _q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*); // tls-psk auth necessary
187 void _q_encryptedBytesWritten(qint64 bytes); // proceed sending
188#endif
189
190 friend class QHttpProtocolHandler;
191};
192
193QT_END_NAMESPACE
194
195#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)
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:316
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