[QGIS-Developer] Do we have a User-Agent string for QGIS

Jorge Gustavo Rocha jgr at di.uminho.pt
Sun Apr 8 08:47:32 PDT 2018


Hi Richard,

Yes, we use an User Agent for XYZ requests. The string is exposed in the
settings (Settings → Options → Network). Users can change it. The
default User Agent is "Mozilla/5.0".

Even if the user changes the UserAgent in settings, the string "
QGIS/version" is always added to the User Agent defined. So, the User
Agent is in fact "Mozilla/5.0 QGIS/3.x". See
src/core/qgsnetworkaccessmanager.cpp

  QString userAgent = s.value( QStringLiteral(
"/qgis/networkAndProxy/userAgent" ), "Mozilla/5.0" ).toString();
  if ( !userAgent.isEmpty() )
    userAgent += ' ';
  userAgent += QStringLiteral( "QGIS/%1" ).arg( Qgis::QGIS_VERSION );
  pReq->setRawHeader( "User-Agent", userAgent.toUtf8() );

That is what we have: an User Agent as "Mozilla/5.0 QGIS/3.x".

I think plugins should use the same approach. If some plugin
'misbehaves', we just need to fix it.

Regards,

Jorge Gustavo

On 08-04-2018 13:38, Richard Duivenvoorde wrote:
> Hi,
> 
> Being busy with a Nominatim Locator Filter plugin, which retrieves
> geocoder results from the Nominatim service, I read [0] in the Usage
> Policy that the project asks to provide a proper User-Agent in the
> headers. Same
> 
> My question here:
> - do we already have a 'QGIS-Desktop' User-Agent string?
> I read that the tile services (we use the xyz tiles), also ask that [1],
> so we probably (should) have?
> 
> You can put a lot of info in it [2], but I could just add a plugin
> string like: "QGIS-Nominatim-Locator-Plugin".
> 
> OR would it be better to do it project wide: like there would be a
> 'iface.getUserAgentString()'
> which could create much more interesting User-Agent like:
> "QGIS/3.1 (x86_64 GNU/Linux, nl, Qt 5.9.2, GDAL 2.2.4)"
> Or so...
> 
> Mmm, now thinking about it, it is probably better if I just use my own
> User-Agent for a plugin, then when the plugin 'misbehaves', it is not
> the QGIS-project that is blamed for it?
> 
> Or is is better to have one 'face' to the rest of the world.
> 
> Anybody?
> 
> Regards,
> 
> Richard Duivenvoorde
> 
> 
> 
> [0] https://operations.osmfoundation.org/policies/nominatim/
> [1] https://operations.osmfoundation.org/policies/tiles/
> [2] https://en.wikipedia.org/wiki/User_agent
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 

J. Gustavo
-- 
Jorge Gustavo Rocha
Departamento de Informática
Universidade do Minho
4710-057 Braga
Tel: +351 253604480
Fax: +351 253604471
Móvel: +351 910333888
skype: nabocudnosor



More information about the QGIS-Developer mailing list