5#include <private/qabstractsocket_p.h>
7#include "private/qnoncontiguousbytedevice_p.h"
8#include <private/qnetworkrequest_p.h>
9#include <private/qobject_p.h>
10#include <private/qauthenticator_p.h>
11#include "private/qhostinfo_p.h"
15#include <private/qdecompresshelper_p.h>
22# include <private/qsslsocket_p.h>
23# include <QtNetwork/qsslkey.h>
24# include <QtNetwork/qsslcipher.h>
25# include <QtNetwork/qsslconfiguration.h>
26# include <QtNetwork/qsslerror.h>
50 hostName(hostName),
port(
port), encrypt(encrypt), delayIpv4(true)
53 ? 1 : defaultHttpChannelCount)
54 , channelCount(defaultHttpChannelCount)
55#ifndef QT_NO_NETWORKPROXY
58 , preConnectRequests(0)
59 , connectionType(
type)
72 hostName(hostName),
port(
port), encrypt(encrypt), delayIpv4(true),
73 channelCount(connectionCount)
74#ifndef QT_NO_NETWORKPROXY
77 , preConnectRequests(0)
78 , connectionType(
type)
84 ? 1 : connectionCount;
163 qFatal(
"Called with unknown socket object.");
175 bool emitError =
true;
177 int otherSocket = (
i == 0 ? 1 : 0);
212 qWarning(
"We got a connection error when networkLayerState is Unknown");
221 return reply.d_func()->responseData.byteAmount();
226 return reply.d_func()->responseData.sizeNextBlock();
239 if (uploadByteDevice) {
241 const qint64 uploadDeviceSize = uploadByteDevice->
size();
242 if (contentLength != -1 && uploadDeviceSize != -1) {
244 if (uploadDeviceSize < contentLength)
245 request.setContentLength(uploadDeviceSize);
246 }
else if (contentLength == -1 && uploadDeviceSize != -1) {
248 request.setContentLength(uploadDeviceSize);
249 }
else if (contentLength != -1 && uploadDeviceSize == -1) {
251 }
else if (
Q_UNLIKELY(contentLength == -1 && uploadDeviceSize == -1)) {
252 qFatal(
"QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given");
257#ifndef QT_NO_NETWORKPROXY
261 request.setHeaderField(
"Proxy-Connection",
"Keep-Alive");
266 request.setHeaderField(
"Connection",
"Keep-Alive");
267#ifndef QT_NO_NETWORKPROXY
277 if (
value.isEmpty()) {
278#ifndef QT_NO_COMPRESS
280 request.setHeaderField(
"Accept-Encoding", acceptedEncoding.join(
", "));
281 request.d->autoDecompress =
true;
284 request.d->autoDecompress =
false;
293 if (
value.isEmpty()) {
302 request.setHeaderField(
"Accept-Language", std::move(acceptLanguage).toLatin1());
308 request.setHeaderField(
"User-Agent",
"Mozilla/5.0");
311 if (
value.isEmpty()) {
330 request.prependHeaderField(
"Host", host);
333 reply->d_func()->requestIsPrepared =
true;
354 reply->d_func()->eraseData();
376 if (fromChannel >= 0) {
388 if (
i == fromChannel)
405 bool isProxy,
bool &resend)
415 const QByteArray header = isProxy ?
"proxy-authenticate" :
"www-authenticate";
417 const bool isSupported = std::any_of(authenticationMethods.begin(), authenticationMethods.end(),
441 if (
channels[
i].authenticationCredentialsSent) {
444 priv->hasFailed =
true;
449#ifndef QT_NO_NETWORKPROXY
454 priv->hasFailed =
true;
513 return std::move(
result.redirectUrl);
545 if (redirectUrl.
scheme() ==
"http"_L1 || redirectUrl.
scheme() ==
"https"_L1) {
555 if (priorUrl.
host() != redirectUrl.
host()
557 || priorUrl.
port() != redirectUrl.
port()) {
564 Q_ASSERT(!
"Unexpected redirect policy");
584 const bool authNeeded =
channel.lastStatus == 401;
585 const bool ntlmNegoOk = ntlmNego && authNeeded
587 || !
channel.authenticationCredentialsSent);
589 !ntlmNego && (authNeeded ||
request.headerField(
"Authorization").isEmpty());
590 if (ntlmNegoOk || otherOk) {
593 request.setHeaderField(
"Authorization", response);
594 channel.authenticationCredentialsSent =
true;
598#if QT_CONFIG(networkproxy)
599 authenticator = &
channel.proxyAuthenticator;
605 const bool proxyAuthNeeded =
channel.lastStatus == 407;
606 const bool ntlmNegoOk = ntlmNego && proxyAuthNeeded
608 const bool otherOk = !ntlmNego;
609 if (ntlmNegoOk || otherOk) {
612 request.setHeaderField(
"Proxy-Authorization", response);
613 channel.proxyCredentialsSent =
true;
626 reply->d_func()->connection =
q;
646 if (!pair.second->d_func()->requestIsPrepared)
674 if (!pair.second->d_func()->requestIsPrepared)
682 if (!pair.second->d_func()->requestIsPrepared)
717 if (!messagePair.second->d_func()->requestIsPrepared)
726 if (!messagePair.second->d_func()->requestIsPrepared)
803 if (!
channels[
i].proxyAuthenticator.isNull()
823 if (lengthBefore ==
channels[
i].alreadyPipelinedRequests.size())
836 if (lengthBefore ==
channels[
i].alreadyPipelinedRequests.size())
850 for (
int i =
queue.size() - 1;
i >= 0; --
i) {
862 if (!
request.isPipeliningAllowed())
871 if (!messagePair.second->d_func()->requestIsPrepared)
873 channel.pipelineInto(messagePair);
928 errorString = extraDetail;
960 if (
reply->isAborted()) {
995 if (
it.value().second ==
reply) {
1008 if (messagePair.second ==
reply) {
1019 if (messagePair.second ==
reply) {
1088 if (
channels[0].h2RequestsToSend.size()) {
1124 int neededOpenChannels = queuedRequests;
1130 if (neededOpenChannels <= 0)
1136 for (
int i = 0; i < activeChannelCount && neededOpenChannels > 0; ++
i) {
1143 neededOpenChannels--;
1150 neededOpenChannels--;
1155 for (
int i = 0; i < activeChannelCount && neededOpenChannels > 0; ++
i) {
1160 neededOpenChannels--;
1163 while (!channelsToConnect.
isEmpty()) {
1199#ifndef QT_NO_NETWORKPROXY
1220 bool immediateResultValid =
false;
1224 &immediateResultValid,
1226 if (immediateResultValid) {
1237 bool foundAddress =
false;
1241 const auto addresses =
info.addresses();
1245 if (!foundAddress) {
1246 foundAddress =
true;
1251 if (!foundAddress) {
1252 foundAddress =
true;
1269#ifndef QT_NO_NETWORKPROXY
1290 qDebug(
"QHttpNetworkConnectionPrivate::_q_hostLookupFinished"
1291 " could not de-queue request, failed to report HostNotFoundError");
1360 connectionType)),
parent)
1395 d->fillHttp2Queue();
1406 return d_func()->channels;
1409#ifndef QT_NO_NETWORKPROXY
1413 d->networkProxy = networkProxy;
1415 if (!
d->networkProxy.user().isEmpty()) {
1416 for (
int i = 0;
i <
d->channelCount; ++
i) {
1417 d->channels[
i].proxyAuthenticator.setUser(
d->networkProxy.user());
1418 d->channels[
i].proxyAuthenticator.setPassword(
d->networkProxy.password());
1426 return d->networkProxy;
1432 for (
int i = 0;
i <
d->channelCount; ++
i)
1433 d->channels[
i].setProxy(networkProxy);
1439 return d->channels[0].proxy;
1446 return d->connectionType;
1452 d->connectionType =
type;
1458 return d->http2Parameters;
1476 for (
int i = 0;
i <
d->activeChannelCount; ++
i)
1477 d->channels[
i].setSslConfiguration(
config);
1483 return d->sslContext;
1489 d->sslContext = std::move(
context);
1501 for (
int i = 0;
i <
d->channelCount; ++
i) {
1502 d->channels[
i].ignoreSslErrors();
1506 d->channels[
channel].ignoreSslErrors();
1519 for (
int i = 0;
i <
d->channelCount; ++
i) {
1520 d->channels[
i].ignoreSslErrors(errors);
1524 d->channels[
channel].ignoreSslErrors(errors);
1532 d_func()->preConnectRequests--;
1538 return d->peerVerifyName;
1544 d->peerVerifyName = peerName;
1557 for (
int i = 0;
i <
d->activeChannelCount;
i++) {
1564 d->connectionMonitor.stopMonitoring();
1567#ifndef QT_NO_NETWORKPROXY
1600#include "moc_qhttpnetworkconnection_p.cpp"
IOBluetoothL2CAPChannel * channel
static void pauseSocketNotifiers(QAbstractSocket *)
static void resumeSocketNotifiers(QAbstractSocket *)
The QAbstractSocket class provides the base functionality common to all socket types.
static constexpr auto IPv4Protocol
QString peerName() const
Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() ...
static constexpr auto AnyIPProtocol
void close() override
Closes the I/O device for the socket and calls disconnectFromHost() to close the socket's connection.
SocketState state() const
Returns the state of the socket.
static constexpr auto IPv6Protocol
static bool isMethodSupported(QByteArrayView method)
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
The QAuthenticator class provides an authentication object.
QString user() const
Returns the user used for authentication.
void setPassword(const QString &password)
Sets the password used for authentication.
QString password() const
Returns the password used for authentication.
bool isNull() const
Returns true if the object has not been initialized.
void setUser(const QString &user)
Sets the user used for authentication.
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
static constexpr QChar fromLatin1(char c) noexcept
Converts the Latin-1 character c to its equivalent QChar.
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
static QByteArrayList acceptedEncoding()
The QHostAddress class provides an IP address.
void setAddress(quint32 ip4Addr)
Set the IPv4 address specified by ip4Addr.
NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
The QHostInfo class provides static functions for host name lookups.
The QHttp2Configuration class controls HTTP/2 parameters and settings.
std::unique_ptr< QAbstractProtocolHandler > protocolHandler
QAuthenticator proxyAuthenticator
void requeueCurrentlyPipelinedRequests()
QAbstractSocket::NetworkLayerProtocol networkLayerPreference
bool proxyCredentialsSent
QHttpNetworkReply * reply
QHttpNetworkRequest request
QMultiMap< int, HttpMessagePair > h2RequestsToSend
void setConnection(QHttpNetworkConnection *c)
@ PipeliningProbablySupported
bool authenticationCredentialsSent
QList< HttpMessagePair > alreadyPipelinedRequests
QAuthenticator authenticator
QHttpNetworkConnection::ConnectionType connectionType
qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const
void startNetworkLayerStateLookup()
static const int defaultHttpChannelCount
int indexOf(QAbstractSocket *socket) const
QHttpNetworkRequest predictNextRequest() const
void prepareRequest(HttpMessagePair &request)
void startHostInfoLookup()
void emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator *auth)
NetworkLayerPreferenceState networkLayerState
QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt, QHttpNetworkConnection::ConnectionType type)
void copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy)
QString errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket, const QString &extraDetail=QString())
void createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request)
void _q_connectDelayedChannel()
QHttpNetworkConnectionChannel * channels
bool shouldEmitChannelError(QAbstractSocket *socket)
static const int defaultRePipelineLength
void networkLayerDetected(QAbstractSocket::NetworkLayerProtocol protocol)
void _q_startNextRequest()
void requeueRequest(const HttpMessagePair &pair)
QList< HttpMessagePair > lowPriorityQueue
void removeReply(QHttpNetworkReply *reply)
void _q_hostLookupFinished(const QHostInfo &info)
bool dequeueRequest(QAbstractSocket *socket)
QHttpNetworkReply * predictNextRequestsReply() const
QList< HttpMessagePair > highPriorityQueue
void updateChannel(int i, const HttpMessagePair &messagePair)
void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode)
bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend)
QHttpNetworkReply * queueRequest(const QHttpNetworkRequest &request)
void readMoreLater(QHttpNetworkReply *reply)
void fillPipeline(QAbstractSocket *socket)
QTimer delayedConnectionTimer
QNetworkProxy networkProxy
~QHttpNetworkConnectionPrivate()
qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const
static const int defaultPipelineLength
ParseRedirectResult parseRedirectResponse(QHttpNetworkReply *reply)
void preConnectFinished()
QHttpNetworkReply * sendRequest(const QHttpNetworkRequest &request)
void onlineStateChanged(bool isOnline)
QHttp2Configuration http2Parameters() const
void setCacheProxy(const QNetworkProxy &networkProxy)
ConnectionType connectionType()
QNetworkProxy cacheProxy() const
QHttpNetworkConnectionChannel * channels() const
void setPeerVerifyName(const QString &peerName)
void setConnectionType(ConnectionType type)
QString peerVerifyName() const
QHttpNetworkConnection(const QString &hostName, quint16 port=80, bool encrypt=false, ConnectionType connectionType=ConnectionTypeHTTP, QObject *parent=nullptr)
QNetworkProxy transparentProxy() const
~QHttpNetworkConnection()
std::shared_ptr< QSslContext > sslContext()
@ ConnectionTypeHTTP2Direct
void setSslContext(std::shared_ptr< QSslContext > context)
void setTransparentProxy(const QNetworkProxy &networkProxy)
void setHttp2Parameters(const QHttp2Configuration ¶ms)
void ignoreSslErrors(int channel=-1)
void setSslConfiguration(const QSslConfiguration &config)
void readyRead()
This signal is emitted once every time new data is available for reading from the device's current re...
QString errorString() const
Returns a human-readable description of the last device error that occurred.
qsizetype size() const noexcept
bool isEmpty() const noexcept
void removeAt(qsizetype i)
const_reference at(qsizetype i) const noexcept
void prepend(rvalue_ref t)
QString name() const
The short name of this locale.
static QLocale system()
Returns a QLocale object initialized to the system locale.
iterator insert(const Key &key, const T &value)
size_type remove(const Key &key)
const_iterator cbegin() const
void reachabilityChanged(bool isOnline)
The QNetworkProxy class provides a network layer proxy.
Capabilities capabilities() const
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
QString hostName() const
Returns the host name of the proxy host.
@ HostNameLookupCapability
QPair< QByteArray, QByteArray > RawHeaderPair
RawHeaderPair is a QPair<QByteArray, QByteArray> where the first QByteArray is the header name and th...
QVariant header(QNetworkRequest::KnownHeaders header) const
Returns the value of the known header header, if that header was sent by the remote server.
void setRequest(const QNetworkRequest &request)
Sets the associated request for this object to be request.
NetworkError
Indicates all possible error conditions found during the processing of the request.
@ TemporaryNetworkFailureError
@ SslHandshakeFailedError
@ ProxyAuthenticationRequiredError
@ AuthenticationRequiredError
QNetworkRequest request() const
Returns the request that was posted for this reply.
QUrl url() const
Returns the URL of the content downloaded or uploaded.
Priority priority() const
@ SameOriginRedirectPolicy
@ UserVerifiedRedirectPolicy
@ NoLessSafeRedirectPolicy
QUrl url() const
Returns the URL this network request is referring to.
virtual qint64 size() const =0
Returns the size of the complete device or -1 if unknown.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
void enqueue(const T &t)
Adds value t to the tail of the queue.
T dequeue()
Removes the head item in the queue and returns it.
The QSslConfiguration class holds the configuration and state of an SSL connection.
static void resumeSocketNotifiers(QSslSocket *)
static void pauseSocketNotifiers(QSslSocket *)
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
QString first(qsizetype n) const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
void setSingleShot(bool singleShot)
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
void stop()
Stops the timer.
QString userInfo(ComponentFormattingOptions options=PrettyDecoded) const
Returns the user info of the URL, or an empty string if the user info is undefined.
static QByteArray toAce(const QString &domain, AceProcessingOptions options={})
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
QString host(ComponentFormattingOptions=FullyDecoded) const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
QString scheme() const
Returns the scheme of the URL.
int port(int defaultPort=-1) const
static QUrl fromEncoded(QByteArrayView input, ParsingMode mode=TolerantMode)
Parses input and returns the corresponding QUrl.
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char *member, bool *valid, int *id)
QPair< QHttpNetworkRequest, QHttpNetworkReply * > HttpMessagePair
static const QSystemLocale * systemLocale()
constexpr const T & qMax(const T &a, const T &b)
GLbitfield GLuint64 timeout
[4]
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal)
#define QStringLiteral(str)
QFileInfo info(fileName)
[8]
QNetworkRequest request(url)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent