Repository navigation
Set a Wikimedia-compliant User-Agent in stream_file - #353
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #353 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 42 42
Lines 2720 2728 +8
Branches 404 405 +1
=========================================
+ Hits 2720 2728 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix #214
When
stream_filedownloads fromupload.wikimedia.org, it now sets a Wikimedia-compliantUser-Agent(zimscraperlib/<version> (<contact>)) unless the caller already provided one (whatever the casing). This makes scrapers compliant with the Wikimedia User-Agent policy without each of them having to remember it.Behavior for all other hosts is left untouched, so existing callers keep sending no
User-Agentby default.Scrapers that want to advertise their own identity (e.g.
myscraper/1.0 (contact) zimscraperlib/x.y.z) can still pass it throughheaders, like maps2zim currently does with its own wrapper. Happy to add a dedicated parameter or a module-level configuration if you'd prefer that instead of relying onheaders.Changes:
constants.py: newWIKIMEDIA_UPLOAD_HOSTconstant.download.py: two small helpers (is_wikimedia_upload_url,has_user_agent_header) and the defaultUser-Agentapplied forupload.wikimedia.org.stream_filebehavior (default UA applied, custom UA preserved, extra headers merged).