diff options
Diffstat (limited to 'src/network/access')
-rw-r--r-- | src/network/access/qhttpthreaddelegate.cpp | 25 | ||||
-rw-r--r-- | src/network/access/qnetworkcookie.cpp | 36 | ||||
-rw-r--r-- | src/network/access/qnetworkreply.cpp | 18 | ||||
-rw-r--r-- | src/network/access/qnetworkreply.h | 10 |
4 files changed, 76 insertions, 13 deletions
diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index ee3911c72c..b7e8bb3f72 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -60,6 +60,10 @@ static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const QNetworkReply::NetworkError code; // we've got an error switch (httpStatusCode) { + case 400: // Bad Request + code = QNetworkReply::ProtocolInvalidOperationError; + break; + case 401: // Authorization required code = QNetworkReply::AuthenticationRequiredError; break; @@ -80,15 +84,34 @@ static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const code = QNetworkReply::ProxyAuthenticationRequiredError; break; + case 409: // Resource Conflict + code = QNetworkReply::ContentConflictError; + break; + + case 410: // Content no longer available + code = QNetworkReply::ContentGoneError; + break; + case 418: // I'm a teapot code = QNetworkReply::ProtocolInvalidOperationError; break; + case 500: // Internal Server Error + code = QNetworkReply::InternalServerError; + break; + + case 501: // Server does not support this functionality + code = QNetworkReply::OperationNotImplementedError; + break; + + case 503: // Service unavailable + code = QNetworkReply::ServiceUnavailableError; + break; default: if (httpStatusCode > 500) { // some kind of server error - code = QNetworkReply::ProtocolUnknownError; + code = QNetworkReply::UnknownServerError; } else if (httpStatusCode >= 400) { // content error we did not handle above code = QNetworkReply::UnknownContentError; diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index a871c04d56..664bc8282c 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -51,6 +51,7 @@ #include "QtCore/qstring.h" #include "QtCore/qstringlist.h" #include "QtCore/qurl.h" +#include "QtNetwork/qhostaddress.h" #include "private/qobject_p.h" QT_BEGIN_NAMESPACE @@ -466,12 +467,19 @@ QByteArray QNetworkCookie::toRawForm(RawForm form) const } if (!d->domain.isEmpty()) { result += "; domain="; - QString domainNoDot = d->domain; - if (domainNoDot.startsWith(QLatin1Char('.'))) { + if (d->domain.startsWith(QLatin1Char('.'))) { result += '.'; - domainNoDot = domainNoDot.mid(1); + result += QUrl::toAce(d->domain.mid(1)); + } else { + QHostAddress hostAddr(d->domain); + if (hostAddr.protocol() == QAbstractSocket::IPv6Protocol) { + result += '['; + result += d->domain.toUtf8(); + result += ']'; + } else { + result += QUrl::toAce(d->domain); + } } - result += QUrl::toAce(domainNoDot); } if (!d->path.isEmpty()) { result += "; path="; @@ -1015,14 +1023,20 @@ void QNetworkCookie::normalize(const QUrl &url) d->path = defaultPath; } - if (d->domain.isEmpty()) + if (d->domain.isEmpty()) { d->domain = url.host(); - else if (!d->domain.startsWith(QLatin1Char('.'))) - // Ensure the domain starts with a dot if its field was not empty - // in the HTTP header. There are some servers that forget the - // leading dot and this is actually forbidden according to RFC 2109, - // but all browsers accept it anyway so we do that as well. - d->domain.prepend(QLatin1Char('.')); + } else { + QHostAddress hostAddress(d->domain); + if (hostAddress.protocol() != QAbstractSocket::IPv4Protocol + && hostAddress.protocol() != QAbstractSocket::IPv6Protocol + && !d->domain.startsWith(QLatin1Char('.'))) { + // Ensure the domain starts with a dot if its field was not empty + // in the HTTP header. There are some servers that forget the + // leading dot and this is actually forbidden according to RFC 2109, + // but all browsers accept it anyway so we do that as well. + d->domain.prepend(QLatin1Char('.')); + } + } } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index ba6f706f7a..faa8464463 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -173,6 +173,21 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() again, but this failed for example because the upload data could not be read a second time. + \value ContentConflictError the request could not be completed due + to a conflict with the current state of the resource. + + \value ContentGoneError the requested resource is no longer + available at the server. + + \value InternalServerError the server encountered an unexpected + condition which prevented it from fulfilling the request. + + \value OperationNotImplementedError the server does not support the + functionality required to fulfill the request. + + \value ServiceUnavailableError the server is unable to handle the + request at this time. + \value ProtocolUnknownError the Network Access API cannot honor the request because the protocol is not known @@ -191,6 +206,9 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() \value ProtocolFailure a breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.) + \value UnknownServerError an unknown error related to + the server response was detected + \sa error() */ diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index a7db2d189c..f11a5e816a 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -93,12 +93,20 @@ public: ContentNotFoundError, AuthenticationRequiredError, ContentReSendError, + ContentConflictError, + ContentGoneError, UnknownContentError = 299, // protocol errors ProtocolUnknownError = 301, ProtocolInvalidOperationError, - ProtocolFailure = 399 + ProtocolFailure = 399, + + // Server side errors (401-499) + InternalServerError = 401, + OperationNotImplementedError, + ServiceUnavailableError, + UnknownServerError = 499 }; ~QNetworkReply(); |