QNAM: Add support for more KnownHeaders
Task-Number: QTBUG-17267 Change-Id: I32b41d26411ee3a7162bb658d69363a5eeb37230 Reviewed-on: http://codereview.qt.nokia.com/1327 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Petersson <Martin.Petersson@nokia.com>
This commit is contained in:
parent
62481fe9f6
commit
948d051fb1
@ -105,6 +105,10 @@ QT_BEGIN_NAMESPACE
|
||||
header and contains a QList<QNetworkCookie> representing the
|
||||
cookies sent by the server to be stored locally.
|
||||
|
||||
\value UserAgentHeader The User-Agent header sent by HTTP clients.
|
||||
|
||||
\value ServerHeader The Server header received by HTTP clients.
|
||||
|
||||
\sa header(), setHeader(), rawHeader(), setRawHeader()
|
||||
*/
|
||||
|
||||
@ -650,6 +654,12 @@ static QByteArray headerName(QNetworkRequest::KnownHeaders header)
|
||||
case QNetworkRequest::ContentDispositionHeader:
|
||||
return "Content-Disposition";
|
||||
|
||||
case QNetworkRequest::UserAgentHeader:
|
||||
return "User-Agent";
|
||||
|
||||
case QNetworkRequest::ServerHeader:
|
||||
return "Server";
|
||||
|
||||
// no default:
|
||||
// if new values are added, this will generate a compiler warning
|
||||
}
|
||||
@ -663,6 +673,8 @@ static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVaria
|
||||
case QNetworkRequest::ContentTypeHeader:
|
||||
case QNetworkRequest::ContentLengthHeader:
|
||||
case QNetworkRequest::ContentDispositionHeader:
|
||||
case QNetworkRequest::UserAgentHeader:
|
||||
case QNetworkRequest::ServerHeader:
|
||||
return value.toByteArray();
|
||||
|
||||
case QNetworkRequest::LocationHeader:
|
||||
@ -745,6 +757,13 @@ static QNetworkRequest::KnownHeaders parseHeaderName(const QByteArray &headerNam
|
||||
case 's':
|
||||
if (qstricmp(headerName.constData(), "set-cookie") == 0)
|
||||
return QNetworkRequest::SetCookieHeader;
|
||||
else if (qstricmp(headerName.constData(), "server") == 0)
|
||||
return QNetworkRequest::ServerHeader;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
if (qstricmp(headerName.constData(), "user-agent") == 0)
|
||||
return QNetworkRequest::UserAgentHeader;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -778,6 +797,8 @@ static QVariant parseHeaderValue(QNetworkRequest::KnownHeaders header, const QBy
|
||||
{
|
||||
// header is always a valid value
|
||||
switch (header) {
|
||||
case QNetworkRequest::UserAgentHeader:
|
||||
case QNetworkRequest::ServerHeader:
|
||||
case QNetworkRequest::ContentTypeHeader:
|
||||
// copy exactly, convert to QString
|
||||
return QString::fromLatin1(value);
|
||||
|
@ -66,7 +66,9 @@ public:
|
||||
LastModifiedHeader,
|
||||
CookieHeader,
|
||||
SetCookieHeader,
|
||||
ContentDispositionHeader // added for QMultipartMessage
|
||||
ContentDispositionHeader, // added for QMultipartMessage
|
||||
UserAgentHeader,
|
||||
ServerHeader
|
||||
};
|
||||
enum Attribute {
|
||||
HttpStatusCodeAttribute,
|
||||
|
@ -378,6 +378,8 @@ private Q_SLOTS:
|
||||
|
||||
void dontInsertPartialContentIntoTheCache();
|
||||
|
||||
void httpUserAgent();
|
||||
|
||||
// NOTE: This test must be last!
|
||||
void parentingRepliesToTheApp();
|
||||
};
|
||||
@ -1601,6 +1603,11 @@ void tst_QNetworkReply::getFromHttp()
|
||||
// only compare when the header is set.
|
||||
if (reply->header(QNetworkRequest::ContentLengthHeader).isValid())
|
||||
QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), reference.size());
|
||||
|
||||
// We know our internal server is apache..
|
||||
if (qstrcmp(QTest::currentDataTag(), "success-internal") == 0)
|
||||
QVERIFY(reply->header(QNetworkRequest::ServerHeader).toString().contains("Apache"));
|
||||
|
||||
QCOMPARE(reply->readAll(), reference.readAll());
|
||||
}
|
||||
|
||||
@ -6312,6 +6319,25 @@ void tst_QNetworkReply::dontInsertPartialContentIntoTheCache()
|
||||
QCOMPARE(memoryCache->m_insertedUrls.count(), 0);
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::httpUserAgent()
|
||||
{
|
||||
QByteArray response("HTTP/1.0 200 OK\r\n\r\n");
|
||||
MiniHttpServer server(response);
|
||||
server.doClose = true;
|
||||
|
||||
QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, "abcDEFghi");
|
||||
QNetworkReplyPtr reply = manager.get(request);
|
||||
|
||||
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
QTestEventLoop::instance().enterLoop(10);
|
||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
||||
QVERIFY(reply->isFinished());
|
||||
QCOMPARE(reply->error(), QNetworkReply::NoError);
|
||||
QVERIFY(server.receivedData.contains("\r\nUser-Agent: abcDEFghi\r\n"));
|
||||
}
|
||||
|
||||
|
||||
// NOTE: This test must be last testcase in tst_qnetworkreply!
|
||||
void tst_QNetworkReply::parentingRepliesToTheApp()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user