backend: route all outbound User-Agents through core.http_client#218
Merged
Conversation
Follow-up to the shared HTTP session factory: replace the ~20 hardcoded copies of the "ApproachNote/1.0 (+support@approachnote.com)" User-Agent across integration clients, routes, and scripts with make_session() / HTTP_USER_AGENT from core.http_client. One source of truth; a version bump is now a one-line change. - Integration clients (apple_music, wikipedia, coverart, musicbrainz, youtube) and routes/admin: build sessions via make_session(). - core/commons_imagery: drop its local USER_AGENT + make_session, import the shared make_session instead. - Maintenance/one-off scripts: use make_session() or HTTP_USER_AGENT. save_review_thumbs (otherwise standalone) gets a small backend-path bootstrap so it can import the constant. Left intentionally untouched: scripts/onetime_scripts/jazz_song_research.py uses a browser (Mozilla) User-Agent on purpose to scrape a bot-blocking site. Per-service rate limiting stays in each client. All 629 backend tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Follow-up to the shared HTTP session factory (
core/http_client.py, merged in #217). The outbound User-Agent stringApproachNote/1.0 (+support@approachnote.com)was copy-pasted into ~20 files; this routes every call site throughmake_session()/HTTP_USER_AGENTso there's a single source of truth and a version bump is a one-line change.Changes (17 files, net −34 lines)
Production code
apple_music,wikipedia,coverart,musicbrainz,youtube— build their session viamake_session()(withaccept_json=Falsewhere they didn't set an Accept header).routes/admin.py— MusicBrainz diagnostics session viamake_session().core/commons_imagery.py— dropped its localUSER_AGENTconstant and duplicatemake_session(); imports the shared one.Scripts —
fetch_artist_images,jazzs_match,jazzs_extract,jazzs_match_authorityrecs,add_wikipedia_image,fetch_loc_images,gather_performers_from_mb_for_release,diagnostics/fix_unknown_leaders,onetime_scripts/one_time_song_wiki_introusemake_session().save_review_thumbs(otherwise standalone) gets a small backend-path bootstrap so it can importHTTP_USER_AGENT.Intentionally untouched
scripts/onetime_scripts/jazz_song_research.pyuses a browser (Mozilla/5.0…) User-Agent on purpose to scrape a bot-blocking site.Verification
save_review_thumbs --helpruns (bootstrap resolves).ApproachNote/1.0literal remains outsidecore/http_client.py.🤖 Generated with Claude Code