HTTP internals: move some methods inside HTTP request class

... from the private to the public class, because we need to access
these methods from other classes.

Change-Id: I2c5ea84e0f5d3641c1dc02342348f1022d886249
Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
Peter Hartmann 2014-01-22 17:51:43 +01:00 committed by The Qt Project
parent 4f23f0530a
commit 57f209497c
3 changed files with 14 additions and 12 deletions

View File

@ -512,7 +512,7 @@ void QHttpNetworkConnectionPrivate::createAuthorization(QAbstractSocket *socket,
if ((channels[i].authMethod != QAuthenticatorPrivate::Ntlm && request.headerField("Authorization").isEmpty()) || channels[i].lastStatus == 401) {
QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[i].authenticator);
if (priv && priv->method != QAuthenticatorPrivate::None) {
QByteArray response = priv->calculateResponse(request.d->methodName(), request.d->uri(false));
QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false));
request.setHeaderField("Authorization", response);
channels[i].authenticationCredentialsSent = true;
}
@ -524,7 +524,7 @@ void QHttpNetworkConnectionPrivate::createAuthorization(QAbstractSocket *socket,
if (!(channels[i].proxyAuthMethod == QAuthenticatorPrivate::Ntlm && channels[i].lastStatus != 407)) {
QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[i].proxyAuthenticator);
if (priv && priv->method != QAuthenticatorPrivate::None) {
QByteArray response = priv->calculateResponse(request.d->methodName(), request.d->uri(false));
QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false));
request.setHeaderField("Proxy-Authorization", response);
channels[i].proxyCredentialsSent = true;
}

View File

@ -87,9 +87,9 @@ bool QHttpNetworkRequestPrivate::operator==(const QHttpNetworkRequestPrivate &ot
&& (preConnect == other.preConnect);
}
QByteArray QHttpNetworkRequestPrivate::methodName() const
QByteArray QHttpNetworkRequest::methodName() const
{
switch (operation) {
switch (d->operation) {
case QHttpNetworkRequest::Get:
return "GET";
case QHttpNetworkRequest::Head:
@ -107,24 +107,24 @@ QByteArray QHttpNetworkRequestPrivate::methodName() const
case QHttpNetworkRequest::Connect:
return "CONNECT";
case QHttpNetworkRequest::Custom:
return customVerb;
return d->customVerb;
default:
break;
}
return QByteArray();
}
QByteArray QHttpNetworkRequestPrivate::uri(bool throughProxy) const
QByteArray QHttpNetworkRequest::uri(bool throughProxy) const
{
QUrl::FormattingOptions format(QUrl::RemoveFragment | QUrl::RemoveUserInfo | QUrl::FullyEncoded);
// for POST, query data is send as content
if (operation == QHttpNetworkRequest::Post && !uploadByteDevice)
if (d->operation == QHttpNetworkRequest::Post && !d->uploadByteDevice)
format |= QUrl::RemoveQuery;
// for requests through proxy, the Request-URI contains full url
if (!throughProxy)
format |= QUrl::RemoveScheme | QUrl::RemoveAuthority;
QUrl copy = url;
QUrl copy = d->url;
if (copy.path().isEmpty())
copy.setPath(QStringLiteral("/"));
QByteArray uri = copy.toEncoded(format);
@ -137,9 +137,9 @@ QByteArray QHttpNetworkRequestPrivate::header(const QHttpNetworkRequest &request
QByteArray ba;
ba.reserve(40 + fields.length()*25); // very rough lower bound estimation
ba += request.d->methodName();
ba += request.methodName();
ba += ' ';
ba += request.d->uri(throughProxy);
ba += request.uri(throughProxy);
ba += " HTTP/";
ba += QByteArray::number(request.majorVersion());

View File

@ -126,11 +126,15 @@ public:
void setUploadByteDevice(QNonContiguousByteDevice *bd);
QNonContiguousByteDevice* uploadByteDevice() const;
QByteArray methodName() const;
QByteArray uri(bool throughProxy) const;
private:
QSharedDataPointer<QHttpNetworkRequestPrivate> d;
friend class QHttpNetworkRequestPrivate;
friend class QHttpNetworkConnectionPrivate;
friend class QHttpNetworkConnectionChannel;
friend class QHttpProtocolHandler;
};
class QHttpNetworkRequestPrivate : public QHttpNetworkHeaderPrivate
@ -141,8 +145,6 @@ public:
QHttpNetworkRequestPrivate(const QHttpNetworkRequestPrivate &other);
~QHttpNetworkRequestPrivate();
bool operator==(const QHttpNetworkRequestPrivate &other) const;
QByteArray methodName() const;
QByteArray uri(bool throughProxy) const;
static QByteArray header(const QHttpNetworkRequest &request, bool throughProxy);