Skip to content

Commit b1d23c8

Browse files
author
warrior-hub
committed
Add configurable User-Agent for web requests
1 parent 32d9724 commit b1d23c8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

vulnerablecode/http.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import requests
2+
from vulnerablecode.settings import VULNERABLECODE_USER_AGENT
3+
4+
5+
def get(url, **kwargs):
6+
headers = kwargs.pop("headers", {})
7+
headers.setdefault("User-Agent", VULNERABLECODE_USER_AGENT)
8+
return requests.get(url, headers=headers, **kwargs)

vulnerablecode/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,10 @@
385385
"DEFAULT_TIMEOUT": env.int("VULNERABLECODE_REDIS_DEFAULT_TIMEOUT", default=3600),
386386
}
387387
}
388+
389+
import os
390+
391+
VULNERABLECODE_USER_AGENT = os.getenv(
392+
"VULNERABLECODE_USER_AGENT",
393+
"VulnerableCode"
394+
)

0 commit comments

Comments
 (0)