Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Identify the crawler when it posts results to the API

Claude545162919fff
diff --git a/mwmbl/crawl.py b/mwmbl/crawl.py
index df63118..a251231 100644
--- a/mwmbl/crawl.py
+++ b/mwmbl/crawl.py
@@ -454,7 +454,7 @@ class Crawler:
response = requests.post(
results_url,
json=results.dict(),
- headers={"X-API-Key": MWMBL_API_KEY},
+ headers={"X-API-Key": MWMBL_API_KEY, "User-Agent": api_user_agent(_username)},
timeout=RESULTS_POST_TIMEOUT_SECONDS,
)
logger.info(f"Response: {response.text}")
diff --git a/test/test_crawl_promotion.py b/test/test_crawl_promotion.py
index 62fefd1..54c2cec 100644
--- a/test/test_crawl_promotion.py
+++ b/test/test_crawl_promotion.py
@@ -179,7 +179,11 @@ def test_run_indexing_submits_results_that_beat_the_remote_index(fake_redis):
def test_run_indexing_sends_the_api_key_in_the_header(fake_redis):
post = run_indexing_with(fake_redis, [STRONG], [MEDIUM])
- assert post.call_args.kwargs["headers"] == {"X-API-Key": "test-api-key"}
+ headers = post.call_args.kwargs["headers"]
+ assert headers["X-API-Key"] == "test-api-key"
+ # Our own API gets the crawler's API identity, not the contact address meant for
+ # third-party sites.
+ assert headers["User-Agent"].startswith("mwmbl-crawler/")
assert post.call_args.kwargs["json"]["api_key"] is None