summaryrefslogtreecommitdiffstats
path: root/tests/manual/qnetworkaccessmanager/qget/qget.cpp
diff options
context:
space:
mode:
authorShane Kearns <ext-shane.2.kearns@nokia.com>2012-04-24 15:57:24 +0100
committerQt by Nokia <qt-info@nokia.com>2012-05-05 03:50:41 +0200
commit32adb82741b0a4851624b2e6b441b8d83fe6daf0 (patch)
treef09976a30c716ed20ca9403567ea57a51d198ae0 /tests/manual/qnetworkaccessmanager/qget/qget.cpp
parent1aeaf0e7089c893a927a5ab311a6176aad5874a7 (diff)
Enable specifying raw headers for the request
Use "--headers=file" where the file contains the raw headers to send. This is useful for replaying requests from log files. Change-Id: I3bbe582d96fc9797f692a0d5772e8164f8265ce0 Reviewed-by: Martin Petersson <Martin.Petersson@nokia.com>
Diffstat (limited to 'tests/manual/qnetworkaccessmanager/qget/qget.cpp')
-rw-r--r--tests/manual/qnetworkaccessmanager/qget/qget.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/manual/qnetworkaccessmanager/qget/qget.cpp b/tests/manual/qnetworkaccessmanager/qget/qget.cpp
index cd98eff935..7bc0529e16 100644
--- a/tests/manual/qnetworkaccessmanager/qget/qget.cpp
+++ b/tests/manual/qnetworkaccessmanager/qget/qget.cpp
@@ -74,6 +74,7 @@ void printUsage()
<< " ,socks SOCKS5 proxy" << endl
<< " ,ftp FTP proxy" << endl
<< " ,httpcaching HTTP caching proxy (no CONNECT method)" << endl
+ << "--headers=filename Set request headers from file contents" << endl
<< "--post=filename upload the file to the next url using HTTP POST" << endl
<< "--put=filename upload the file to the next url using HTTP PUT" << endl
<< "--content-type=<MIME> set content-type header for upload" << endl
@@ -96,6 +97,7 @@ int main(int argc, char *argv[])
QString contentType;
QString httpUser;
QString httpPassword;
+ QString headersFile;
TransferItem::Method method = TransferItem::Get;
//arguments match wget where possible
foreach (QString str, app.arguments().mid(1)) {
@@ -161,19 +163,43 @@ int main(int argc, char *argv[])
}
else if (str.startsWith("--content-type="))
contentType=str.mid(15);
+ else if (str.startsWith("--headers="))
+ headersFile=str.mid(10);
else if (str == "--serial")
dl.setQueueMode(DownloadManager::Serial);
else if (str.startsWith("-"))
qDebug() << "unsupported option" << str;
else {
QUrl url(QUrl::fromUserInput(str));
+ QNetworkRequest request(url);
+ //set headers
+ if (!headersFile.isEmpty()) {
+ QFile f(headersFile);
+ if (!f.open(QFile::ReadOnly | QFile::Text)) {
+ qDebug() << "can't open headers file: " << headersFile;
+ } else {
+ while (!f.atEnd()) {
+ QByteArray line = f.readLine().trimmed();
+ if (line.isEmpty()) break;
+ int colon = line.indexOf(':');
+ qDebug() << line;
+ if (colon > 0 && colon < line.length() - 2) {
+ request.setRawHeader(line.left(colon), line.mid(colon+2));
+ }
+ }
+ f.close();
+ }
+ }
+ if (!contentType.isEmpty())
+ request.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
+
switch (method) {
case TransferItem::Put:
case TransferItem::Post:
- dl.upload(url, httpUser, httpPassword, uploadFileName, contentType, method);
+ dl.upload(request, httpUser, httpPassword, uploadFileName, method);
break;
case TransferItem::Get:
- dl.get(url, httpUser, httpPassword);
+ dl.get(request, httpUser, httpPassword);
break;
}
method = TransferItem::Get; //default for urls without a request type before it