Skip to content

Commit ea43c2c

Browse files
author
gsherman
committedOct 23, 2008
Add user-agent to WMS requests
git-svn-id: http://svn.osgeo.org/qgis/trunk@9520 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a5dfbbb commit ea43c2c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed
 

‎src/core/qgshttptransaction.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "qgshttptransaction.h"
2525
#include "qgslogger.h"
26+
#include "qgsconfig.h"
2627

2728
#include <QApplication>
2829
#include <QUrl>
@@ -77,7 +78,15 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
7778

7879
QUrl qurl( httpurl );
7980

80-
http = new QHttp( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) );
81+
http = new QHttp( );
82+
// Create a header so we can set the user agent (Per WMS RFC).
83+
QHttpRequestHeader header("GET", qurl.host());
84+
// Set host in the header
85+
header.setValue( "Host", qurl.host() );
86+
// Set the user agent to Quantum GIS plus the version name
87+
header.setValue( "User-agent", QString("Quantum GIS - ") + VERSION );
88+
// Set the host in the QHttp object
89+
http->setHost( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) );
8190

8291
if ( httphost.isEmpty() )
8392
{
@@ -107,13 +116,18 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
107116
QString pathAndQuery = httpurl.remove( 0,
108117
httpurl.indexOf( qurl.path() ) );
109118

119+
110120
if ( !postData ) //do request with HTTP GET
111121
{
112-
httpid = http->get( pathAndQuery );
122+
header.setRequest("GET", pathAndQuery);
123+
// do GET using header containing user-agent
124+
httpid = http->request(header);
113125
}
114126
else //do request with HTTP POST
115127
{
116-
httpid = http->post( pathAndQuery, *postData );
128+
header.setRequest("POST", pathAndQuery);
129+
// do POST using header containing user-agent
130+
httpid = http->request(header, *postData);
117131
}
118132

119133
connect( http, SIGNAL( requestStarted( int ) ),

0 commit comments

Comments
 (0)
Please sign in to comment.