Include version in useragent string, make it readonly #4184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
CKAN and NetKAN use a custom useragent string that identifies them uniquely and works well with most web sites (SourceForge's API being a notable exception, see #4172). This can be overridden with the
--net-useragent
command line option, which we use to mark the Inflator as a bot so it can be excluded from SpaceDock download counts (see #3490).Motivation
The useragent string format has a place to put a version:
https://deviceatlas.com/blog/list-of-user-agent-strings
... but currently we don't do that. It would be nice if server operators could tell from their logs what versions of CKAN people are using to download.
In addition, the
--net-useragent
handling is not implemented as well as it could be. The static stringNet.UserAgentString
is effectively treated as a global variable, written and read freely by whatever assorted random code feels like it, which is bad for reliability, threading, tests, etc. Current versions of vscode rightly raise a warning about this.Changes
Net.UserAgentString
isreadonly
and includesMeta.ReleaseVersion
in its default value, so web servers will know which CKAN is being used, and so we can do a future SpaceDock enhancement to track this if we feel like itNet.UserAgentString
instead pass the user's override value through the parameter stack until reaching one of the functions inNet
, which are updated to use the override if passed and fall back toNet.UserAgentString
otherwise.