1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtNetwork module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#ifndef QHTTPNETWORKCONNECTIONCHANNEL_H
43
#define QHTTPNETWORKCONNECTIONCHANNEL_H
49
// This file is not part of the Qt API. It exists for the convenience
50
// of the Network Access API. This header file may change from
51
// version to version without notice, or even be removed.
55
#include <QtNetwork/qnetworkrequest.h>
56
#include <QtNetwork/qnetworkreply.h>
57
#include <QtNetwork/qabstractsocket.h>
59
#include <private/qobject_p.h>
60
#include <qauthenticator.h>
61
#include <qnetworkproxy.h>
64
#include <private/qhttpnetworkheader_p.h>
65
#include <private/qhttpnetworkrequest_p.h>
66
#include <private/qhttpnetworkreply_p.h>
68
#include <private/qhttpnetworkconnection_p.h>
73
# include <QtNetwork/qsslsocket.h>
74
# include <QtNetwork/qsslerror.h>
75
# include <QtNetwork/qsslconfiguration.h>
77
# include <QtNetwork/qtcpsocket.h>
82
class QHttpNetworkRequest;
83
class QHttpNetworkReply;
86
#ifndef HttpMessagePair
87
typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair;
90
class QHttpNetworkConnectionChannel : public QObject {
94
IdleState = 0, // ready to send request
95
ConnectingState = 1, // connecting to host
96
WritingState = 2, // writing the data
97
WaitingState = 4, // waiting for reply
98
ReadingState = 8, // reading the reply
100
BusyState = (ConnectingState|WritingState|WaitingState|ReadingState|ClosingState)
102
QAbstractSocket *socket;
106
QHttpNetworkRequest request; // current request
107
QHttpNetworkReply *reply; // current reply for this request
111
int lastStatus; // last status received on this channel
112
bool pendingEncrypt; // for https (send after encrypted)
113
int reconnectAttempts; // maximum 2 reconnection attempts
114
QAuthenticatorPrivate::Method authMethod;
115
QAuthenticatorPrivate::Method proxyAuthMethod;
116
QAuthenticator authenticator;
117
QAuthenticator proxyAuthenticator;
118
bool authenticationCredentialsSent;
119
bool proxyCredentialsSent;
121
bool ignoreAllSslErrors;
122
QList<QSslError> ignoreSslErrorsList;
123
QSslConfiguration sslConfiguration;
124
void ignoreSslErrors();
125
void ignoreSslErrors(const QList<QSslError> &errors);
126
void setSslConfiguration(const QSslConfiguration &config);
128
#ifndef QT_NO_BEARERMANAGEMENT
129
QSharedPointer<QNetworkSession> networkSession;
132
// HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining
133
enum PipeliningSupport {
134
PipeliningSupportUnknown, // default for a new connection
135
PipeliningProbablySupported, // after having received a server response that indicates support
136
PipeliningNotSupported // currently not used
138
PipeliningSupport pipeliningSupported;
139
QList<HttpMessagePair> alreadyPipelinedRequests;
140
QByteArray pipeline; // temporary buffer that gets sent to socket in pipelineFlush
141
void pipelineInto(HttpMessagePair &pair);
142
void pipelineFlush();
143
void requeueCurrentlyPipelinedRequests();
144
void detectPipeliningSupport();
146
QHttpNetworkConnectionChannel();
148
QAbstractSocket::NetworkLayerProtocol networkLayerPreference;
150
void setConnection(QHttpNetworkConnection *c);
151
QPointer<QHttpNetworkConnection> connection;
153
#ifndef QT_NO_NETWORKPROXY
155
void setProxy(const QNetworkProxy &networkProxy);
163
bool ensureConnection();
165
void allDone(); // reply header + body have been read
166
void handleStatus(); // called from allDone()
168
bool resetUploadData(); // return true if resetting worked or there is no upload data
170
void handleUnexpectedEOF();
171
void closeAndResendCurrentRequest();
173
bool isSocketBusy() const;
174
bool isSocketWriting() const;
175
bool isSocketWaiting() const;
176
bool isSocketReading() const;
179
void _q_receiveReply();
180
void _q_bytesWritten(qint64 bytes); // proceed sending
181
void _q_readyRead(); // pending data to read
182
void _q_disconnected(); // disconnected from host
183
void _q_connected(); // start sending request
184
void _q_error(QAbstractSocket::SocketError); // error from socket
185
#ifndef QT_NO_NETWORKPROXY
186
void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy
189
void _q_uploadDataReadyRead();
192
void _q_encrypted(); // start sending request (https)
193
void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket
194
void _q_encryptedBytesWritten(qint64 bytes); // proceed sending