8#include "private/qnoncontiguousbytedevice_p.h"
12#include <private/qhttp2protocolhandler_p.h>
13#include <private/qhttpprotocolhandler_p.h>
14#include <private/http2protocol_p.h>
15#include <private/qsocketabstraction_p.h>
18# include <private/qsslsocket_p.h>
19# include <QtNetwork/qsslkey.h>
20# include <QtNetwork/qsslcipher.h>
23#include "private/qnetconmonitor_p.h"
54 , isInitialized(
false)
59 , resendCurrent(
false)
61 , pendingEncrypt(
false)
63 , authenticationCredentialsSent(
false)
64 , proxyCredentialsSent(
false)
67 , ignoreAllSslErrors(
false)
69 , pipeliningSupported(PipeliningSupportUnknown)
89#ifndef QT_NO_NETWORKPROXY
91 if (
auto s = qobject_cast<QAbstractSocket *>(
socket))
107 using SocketType = std::remove_pointer_t<
decltype(
socket)>;
121 if constexpr (std::is_same_v<SocketType, QAbstractSocket>) {
125 }
else if constexpr (std::is_same_v<SocketType, QLocalSocket>) {
130 this, std::move(convertAndForward),
137#ifndef QT_NO_NETWORKPROXY
138 if (
auto *
s = qobject_cast<QAbstractSocket *>(
socket)) {
163 sslSocket->ignoreSslErrors();
178#ifndef QT_NO_NETWORKPROXY
179 if (
auto *
s = qobject_cast<QAbstractSocket *>(
socket);
226 auto callAbort = [](
auto *
s) {
284 reply->d_func()->clear();
286 reply->d_func()->connectionChannel =
this;
329 priv->hasFailed =
false;
332 priv->hasFailed =
false;
351 if (potentialReply) {
357#ifndef QT_NO_NETWORKPROXY
363 if (
auto *abSocket = qobject_cast<QAbstractSocket *>(
socket);
376 value =
connection->d_func()->predictNextRequest().headerField(
"user-agent");
381 if (!
value.isEmpty()) {
386 abSocket->setProxy(
proxy);
403 sslSocket->ignoreSslErrors();
409 sslSocket->setReadBufferSize(64*1024);
418#ifndef QT_NO_NETWORKPROXY
423 if (
auto *
s = qobject_cast<QAbstractSocket *>(
socket)) {
424 s->connectToHost(connectHost, connectPort,
428 s->setReadBufferSize(1 * 1024);
429 }
else if (
auto *
s = qobject_cast<QLocalSocket *>(
socket)) {
430 s->connectToServer(connectHost);
432#ifndef QT_NO_NETWORKPROXY
434 auto *
s = qobject_cast<QAbstractSocket *>(
socket);
440 s->setReadBufferSize(64 * 1024);
462 qWarning(
"QHttpNetworkConnectionChannel::allDone() called without reply. Please report at http://bugreports.qt.io/");
483 auto deleter = std::make_unique<ProtocolHandlerDeleter>(oldHandler);
487 deleter->deleteLater();
508 bool emitFinished =
reply->d_func()->shouldEmitSignals();
509 bool connectionCloseEnabled =
reply->d_func()->isConnectionCloseEnabled();
518 if (
reply && emitFinished)
552 reply = messagePair.second;
573 if (connectionCloseEnabled)
576 if (qobject_cast<QHttpNetworkConnection*>(
connection))
590 && (!
reply->d_func()->isConnectionCloseEnabled())
596 && (!serverHeaderField.contains(
"Microsoft-IIS/5."))
597 && (!serverHeaderField.contains(
"Netscape-Enterprise/3."))
599 && (!serverHeaderField.contains(
"WebLogic"))
600 && (!serverHeaderField.startsWith(
"Rocket"))
618 if (qobject_cast<QHttpNetworkConnection*>(
connection))
630 switch (statusCode) {
647 }
else if (qobject_cast<QHttpNetworkConnection *>(
connection)) {
659 reply->d_func()->eraseData();
685 if (qobject_cast<QHttpNetworkConnection*>(
connection))
702 if (!uploadByteDevice->reset()) {
711#ifndef QT_NO_NETWORKPROXY
715 if (
auto *
s = qobject_cast<QAbstractSocket *>(
socket))
716 s->setProxy(networkProxy);
718 proxy = networkProxy;
761 reply->d_func()->clear();
763 reply->d_func()->connectionChannel =
this;
765 reply->d_func()->pipeliningUsed =
true;
767#ifndef QT_NO_NETWORKPROXY
800 if (qobject_cast<QHttpNetworkConnection*>(
connection))
809 if (qobject_cast<QHttpNetworkConnection*>(
connection))
881 if (
connection->d_func()->delayedConnectionTimer.isActive())
882 connection->d_func()->delayedConnectionTimer.stop();
925 auto connectionPrivate =
connection->d_func();
926 if (!connectionPrivate->connectionMonitor.isMonitoring()) {
929 if (connectionPrivate->connectionMonitor.setTargets(absSocket->localAddress(), absSocket->peerAddress()))
930 connectionPrivate->connectionMonitor.startMonitoring();
956 if (tryProtocolUpgrade) {
963 connection->d_func()->dequeueRequest(absSocket);
966 if (tryProtocolUpgrade) {
980 connection->d_func()->dequeueRequest(localSocket);
987 if (
auto *
s = qobject_cast<QAbstractSocket *>(
socket))
989 else if (
auto *
s = qobject_cast<QLocalSocket *>(
socket))
999 switch (socketError) {
1005#ifndef QT_NO_NETWORKPROXY
1046 if (!
reply->d_func()->expectContent()) {
1120 QPointer<QHttpNetworkConnection> that =
connection;
1139 reply->d_func()->httpErrorCode = errorCode;
1145 }
while (!
connection->d_func()->highPriorityQueue.isEmpty()
1146 || !
connection->d_func()->lowPriorityQueue.isEmpty());
1151 for (
const auto &httpMessagePair : h2RequestsToSendCopy) {
1154 currentReply->d_func()->
errorString = errorString;
1155 currentReply->d_func()->httpErrorCode = errorCode;
1157 emit currentReply->finishedWithError(errorCode, errorString);
1178#ifndef QT_NO_NETWORKPROXY
1185 connection->d_func()->emitProxyAuthenticationRequired(
this,
proxy, auth);
1191 connection->d_func()->emitProxyAuthenticationRequired(
this,
proxy, auth);
1208 for (
const auto &httpMessagePair : h2RequestsToSendCopy) {
1211 emit currentReply->finishedWithError(
error, QHttpNetworkConnectionChannel::tr(
message));
1225 switch (sslSocket->sslConfiguration().nextProtocolNegotiationStatus()) {
1227 QByteArray nextProtocol = sslSocket->sslConfiguration().nextNegotiatedProtocol();
1237 "detected unknown Next Protocol Negotiation protocol");
1248 const int nProtocols = protocols.size();
1254 if (nProtocols > protocols.size()) {
1255 newConfiguration.setAllowedNextProtocols(protocols);
1256 const int channelCount =
connection->d_func()->channelCount;
1257 for (
int i = 0;
i < channelCount; ++
i)
1274 "detected unknown Next Protocol Negotiation protocol");
1293 emit pair.second->encrypted();
1314 for (
const auto &httpMessagePair : h2RequestsToSendCopy)
1315 connection->d_func()->requeueRequest(httpMessagePair);
1335 for (
const auto &httpMessagePair : h2RequestsToSendCopy) {
1339 emit currentReply->sslErrors(errors);
1358 for (
const auto &httpMessagePair : h2RequestsToSendCopy) {
1389#include "moc_qhttpnetworkconnectionchannel_p.cpp"
The QAbstractSocket class provides the base functionality common to all socket types.
SocketState
This enum describes the different states in which a socket can be.
static constexpr auto IPv4Protocol
void errorOccurred(QAbstractSocket::SocketError)
void setProxy(const QNetworkProxy &networkProxy)
static constexpr auto AnyIPProtocol
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
SocketError
This enum describes the socket errors that can occur.
@ ProxyConnectionClosedError
@ ProxyConnectionRefusedError
@ ProxyConnectionTimeoutError
@ SslHandshakeFailedError
@ ProxyAuthenticationRequiredError
static constexpr auto IPv6Protocol
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
The QAuthenticator class provides an authentication object.
bool contains(char c) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
void clear()
Clears the contents of the byte array and makes it null.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Q_INVOKABLE void handleConnectionClosure()
bool isSocketReading() const
std::unique_ptr< QAbstractProtocolHandler > protocolHandler
QScopedPointer< QSslConfiguration > sslConfiguration
QAuthenticator proxyAuthenticator
void _q_connected_local_socket(QLocalSocket *socket)
bool isSocketWaiting() const
void setProxy(const QNetworkProxy &networkProxy)
void _q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *)
void requeueCurrentlyPipelinedRequests()
void setSslConfiguration(const QSslConfiguration &config)
QHttpNetworkConnectionChannel()
friend class QHttpProtocolHandler
void handleUnexpectedEOF()
void sendRequestDelayed()
void _q_bytesWritten(qint64 bytes)
QAbstractSocket::NetworkLayerProtocol networkLayerPreference
bool proxyCredentialsSent
void closeAndResendCurrentRequest()
void emitFinishedWithError(QNetworkReply::NetworkError error, const char *message)
void pipelineInto(HttpMessagePair &pair)
void resendCurrentRequest()
void _q_uploadDataReadyRead()
void detectPipeliningSupport()
bool isSocketBusy() const
void _q_encryptedBytesWritten(qint64 bytes)
PipeliningSupport pipeliningSupported
QPointer< QHttpNetworkConnection > connection
QHttpNetworkReply * reply
bool isSocketWriting() const
QHttpNetworkRequest request
QMultiMap< int, HttpMessagePair > h2RequestsToSend
void _q_sslErrors(const QList< QSslError > &errors)
void setConnection(QHttpNetworkConnection *c)
@ PipeliningProbablySupported
@ PipeliningSupportUnknown
void _q_connected_abstract_socket(QAbstractSocket *socket)
void requeueHttp2Requests()
QList< QSslError > ignoreSslErrorsList
bool authenticationCredentialsSent
QList< HttpMessagePair > alreadyPipelinedRequests
void _q_error(QAbstractSocket::SocketError)
void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth)
QAuthenticator authenticator
QHttp2Configuration http2Parameters() const
QNetworkProxy cacheProxy() const
QHttpNetworkConnectionChannel * channels() const
void setConnectionType(ConnectionType type)
QString peerVerifyName() const
QNetworkProxy transparentProxy() const
ConnectionType connectionType() const
@ ConnectionTypeHTTP2Direct
void setSslContext(std::shared_ptr< QSslContext > context)
std::shared_ptr< QSslContext > sslContext() const
QHttpNetworkConnection * connection()
QByteArray headerField(QByteArrayView name, const QByteArray &defaultValue=QByteArray()) const override
QString errorString() const
void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator)
void finishedWithError(QNetworkReply::NetworkError errorCode, const QString &detail=QString())
void setHttp2WasUsed(bool h2Used)
void setReadBufferSize(qint64 size)
void setDownstreamLimited(bool t)
int minorVersion() const override
qint64 contentLength() const override
void setRedirectUrl(const QUrl &url)
void sslErrors(const QList< QSslError > &errors)
int majorVersion() const override
static QByteArray header(const QHttpNetworkRequest &request, bool throughProxy)
QByteArray headerField(QByteArrayView name, const QByteArray &defaultValue=QByteArray()) const override
QUrl url() const override
QNonContiguousByteDevice * uploadByteDevice() const
void readyRead()
This signal is emitted once every time new data is available for reading from the device's current re...
bool isOpen() const
Returns true if the device is open; otherwise returns false.
void bytesWritten(qint64 bytes)
This signal is emitted every time a payload of data has been written to the device's current write ch...
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
void append(parameter_type t)
The QLocalSocket class provides a local socket.
LocalSocketError
The LocalServerError enumeration represents the errors that can occur.
The QNetworkProxy class provides a network layer proxy.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
void setHeaders(const QHttpHeaders &newHeaders)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QHttpHeaders headers() const
NetworkError
Indicates all possible error conditions found during the processing of the request.
@ ProxyConnectionRefusedError
@ ProxyConnectionClosedError
@ SslHandshakeFailedError
@ ProxyAuthenticationRequiredError
@ AuthenticationRequiredError
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
T * data() const noexcept
Returns the value of the pointer referenced by this object.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
The QSslConfiguration class holds the configuration and state of an SSL connection.
QList< QByteArray > allowedNextProtocols() const
bool isNull() const
Returns true if this is a null QSslConfiguration object.
static const char ALPNProtocolHTTP2[]
static const char NextProtocolHttp1_1[]
@ NextProtocolNegotiationNone
@ NextProtocolNegotiationUnsupported
@ NextProtocolNegotiationNegotiated
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
static std::shared_ptr< QSslContext > sslContext(QSslSocket *socket)
static void checkSettingSslContext(QSslSocket *, std::shared_ptr< QSslContext >)
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
void sslErrors(const QList< QSslError > &errors)
QSslSocket emits this signal after the SSL handshake to indicate that one or more errors have occurre...
void encryptedBytesWritten(qint64 totalBytes)
void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator)
void encrypted()
This signal is emitted when QSslSocket enters encrypted mode.
\macro QT_RESTRICTED_CAST_FROM_ASCII
~ProtocolHandlerDeleter()
ProtocolHandlerDeleter(QAbstractProtocolHandler *h)
The QTcpSocket class provides a TCP socket.
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
bool is_protocol_upgraded(const QHttpNetworkReply &reply)
void appendProtocolUpgradeHeaders(const QHttp2Configuration &config, QHttpNetworkRequest *request)
auto visit(Fn &&fn, QIODevice *socket, Args &&...args)
QAbstractSocket::SocketState socketState(QIODevice *device)
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
DBusConnection * connection
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static const int reconnectAttemptsDefault
QPair< QHttpNetworkRequest, QHttpNetworkReply * > HttpMessagePair
GLuint GLsizei const GLchar * message
GLfloat GLfloat GLfloat GLfloat h