Skip to content

Commit

Permalink
Add user-agent to WMS requests
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9520 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
gsherman committed Oct 23, 2008
1 parent a5dfbbb commit ea43c2c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/core/qgshttptransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "qgshttptransaction.h"
#include "qgslogger.h"
#include "qgsconfig.h"

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

QUrl qurl( httpurl );

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

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


if ( !postData ) //do request with HTTP GET
{
httpid = http->get( pathAndQuery );
header.setRequest("GET", pathAndQuery);
// do GET using header containing user-agent
httpid = http->request(header);
}
else //do request with HTTP POST
{
httpid = http->post( pathAndQuery, *postData );
header.setRequest("POST", pathAndQuery);
// do POST using header containing user-agent
httpid = http->request(header, *postData);
}

connect( http, SIGNAL( requestStarted( int ) ),
Expand Down

0 comments on commit ea43c2c

Please sign in to comment.