Discussion:
[QGIS-Developer] Do we have a User-Agent string for QGIS
Richard Duivenvoorde
2018-04-08 12:38:24 UTC
Permalink
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
Jorge Gustavo Rocha
2018-04-08 15:47:32 UTC
Permalink
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
Post by Richard Duivenvoorde
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
- 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()'
"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
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
Tobias Wendorff
2018-04-08 18:30:33 UTC
Permalink
Hi,
Post by Jorge Gustavo Rocha
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".
I've seen quite a lot WMS proxies blocking requests containing
"QGIS" and "GDAL" in user-agent. I like the way it's hardcoded
in QGIS. When a service provider doesn't allow loading his content
into QGIS, the user should accept this and don't easily override
this :)

Just for the notes: actually, there are also blacklists for ArcGIS
clients. It's an easy way to protect web-viewer only WMS from
being loaded or grabbed from a desktop GIS or CLI.

Best regards,
Tobias
Nyall Dawson
2018-04-08 23:37:32 UTC
Permalink
On 9 April 2018 at 04:30, Tobias Wendorff
Post by Tobias Wendorff
Hi,
Post by Jorge Gustavo Rocha
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".
I've seen quite a lot WMS proxies blocking requests containing
"QGIS" and "GDAL" in user-agent. I like the way it's hardcoded
in QGIS. When a service provider doesn't allow loading his content
into QGIS, the user should accept this and don't easily override
this :)
Also fulcrum - for some unknown reason they block direct geojson
access to datasets unless you spoof a standard browser user agent.

(If anyone reading is a paying Fulcrum customer, please hassle them
about this. It's a silly restriction which really negatively impacts
on their otherwise great offering. )

Nyall
Post by Tobias Wendorff
Just for the notes: actually, there are also blacklists for ArcGIS
clients. It's an easy way to protect web-viewer only WMS from
being loaded or grabbed from a desktop GIS or CLI.
Best regards,
Tobias
_______________________________________________
QGIS-Developer mailing list
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Loading...