Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QHTTPNETWORKCONNECTIONCHANNEL_H
5#define QHTTPNETWORKCONNECTIONCHANNEL_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of the Network Access API. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/private/qtnetworkglobal_p.h>
19#include <QtNetwork/qnetworkrequest.h>
20#include <QtNetwork/qnetworkreply.h>
21#include <QtNetwork/qabstractsocket.h>
22#include <QtNetwork/qlocalsocket.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
44#include <QtCore/qpointer.h>
45#include <QtCore/qscopedpointer.h>
46
47#include <memory>
48
50
52
55class QByteArray;
56
57#ifndef HttpMessagePair
58typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair;
59#endif
60
63public:
64 // TODO: Refactor this to add an EncryptingState (and remove pendingEncrypt).
65 // Also add an Unconnected state so IdleState does not have double meaning.
67 IdleState = 0, // ready to send request
68 ConnectingState = 1, // connecting to host
69 WritingState = 2, // writing the data
70 WaitingState = 4, // waiting for reply
71 ReadingState = 8, // reading the reply
74 };
76 bool ssl;
79 QHttpNetworkRequest request; // current request, only used for HTTP
80 QHttpNetworkReply *reply; // current reply for this request, only used for HTTP
84 int lastStatus; // last status received on this channel
85 bool pendingEncrypt; // for https (send after encrypted)
86 int reconnectAttempts; // maximum 2 reconnection attempts
91 std::unique_ptr<QAbstractProtocolHandler> protocolHandler;
92 QMultiMap<int, HttpMessagePair> h2RequestsToSend;
93 bool switchedToHttp2 = false;
94#ifndef QT_NO_SSL
96 QList<QSslError> ignoreSslErrorsList;
97 QScopedPointer<QSslConfiguration> sslConfiguration;
98 void ignoreSslErrors();
99 void ignoreSslErrors(const QList<QSslError> &errors);
101 void requeueHttp2Requests(); // when we wanted HTTP/2 but got HTTP/1.1
102#endif
103 // to emit the signal for all in-flight replies:
105
106 // HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining
108 PipeliningSupportUnknown, // default for a new connection
109 PipeliningProbablySupported, // after having received a server response that indicates support
110 PipeliningNotSupported // currently not used
111 };
113 QList<HttpMessagePair> alreadyPipelinedRequests;
114 QByteArray pipeline; // temporary buffer that gets sent to socket in pipelineFlush
115 void pipelineInto(HttpMessagePair &pair);
116 void pipelineFlush();
119
121
123
125 QPointer<QHttpNetworkConnection> connection;
126
127#ifndef QT_NO_NETWORKPROXY
129 void setProxy(const QNetworkProxy &networkProxy);
130#endif
131
132 void init();
133 void close();
134 void abort();
135
136 bool sendRequest();
137 void sendRequestDelayed();
138
139 bool ensureConnection();
140
141 void allDone(); // reply header + body have been read
142 void handleStatus(); // called from allDone()
143
144 bool resetUploadData(); // return true if resetting worked or there is no upload data
145
146 void handleUnexpectedEOF();
149
150 bool isSocketBusy() const;
151 bool isSocketWriting() const;
152 bool isSocketWaiting() const;
153 bool isSocketReading() const;
154
155 protected slots:
156 void _q_receiveReply();
157 void _q_bytesWritten(qint64 bytes); // proceed sending
158 void _q_readyRead(); // pending data to read
159 void _q_disconnected(); // disconnected from host
162 void _q_connected(); // start sending request
163 void _q_error(QAbstractSocket::SocketError); // error from socket
164#ifndef QT_NO_NETWORKPROXY
165 void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy
166#endif
167
169
170#ifndef QT_NO_SSL
171 void _q_encrypted(); // start sending request (https)
172 void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket
174 void _q_encryptedBytesWritten(qint64 bytes); // proceed sending
175#endif
176
178};
179
181
182#endif
The QAbstractSocket class provides the base functionality common to all socket types.
SocketError
This enum describes the socket errors that can occur.
The QAuthenticator class provides an authentication object.
\inmodule QtCore
Definition qbytearray.h:57
std::unique_ptr< QAbstractProtocolHandler > protocolHandler
QScopedPointer< QSslConfiguration > sslConfiguration
void _q_connected_local_socket(QLocalSocket *socket)
void setProxy(const QNetworkProxy &networkProxy)
void _q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *)
void setSslConfiguration(const QSslConfiguration &config)
QAbstractSocket::NetworkLayerProtocol networkLayerPreference
void emitFinishedWithError(QNetworkReply::NetworkError error, const char *message)
QPointer< QHttpNetworkConnection > connection
QMultiMap< int, HttpMessagePair > h2RequestsToSend
void _q_sslErrors(const QList< QSslError > &errors)
void setConnection(QHttpNetworkConnection *c)
void _q_connected_abstract_socket(QAbstractSocket *socket)
void _q_error(QAbstractSocket::SocketError)
void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth)
\inmodule QtCore \reentrant
Definition qiodevice.h:34
The QLocalSocket class provides a local socket.
The QNetworkProxy class provides a network layer proxy.
NetworkError
Indicates all possible error conditions found during the processing of the request.
\inmodule QtCore
Definition qobject.h:103
The QSslConfiguration class holds the configuration and state of an SSL connection.
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
EGLConfig config
QPair< QHttpNetworkRequest, QHttpNetworkReply * > HttpMessagePair
GLuint GLsizei const GLchar * message
const GLubyte * c
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define slots
long long qint64
Definition qtypes.h:60