mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-15 14:22:43 +00:00
test(models): preserve catalog urlopen monkeypatches
This commit is contained in:
parent
5415b77658
commit
b8dd1bf3a5
1 changed files with 4 additions and 0 deletions
|
|
@ -37,6 +37,8 @@ _CREDENTIAL_REDIRECT_HEADERS = {
|
|||
"cookie",
|
||||
}
|
||||
|
||||
_ORIGINAL_URLOPEN = urllib.request.urlopen
|
||||
|
||||
|
||||
class _StripCredentialRedirectHandler(urllib.request.HTTPRedirectHandler):
|
||||
"""Drop credential headers when urllib follows redirects to another host."""
|
||||
|
|
@ -57,6 +59,8 @@ class _StripCredentialRedirectHandler(urllib.request.HTTPRedirectHandler):
|
|||
|
||||
|
||||
def _urlopen_model_catalog_request(req: urllib.request.Request, *, timeout: float):
|
||||
if urllib.request.urlopen is not _ORIGINAL_URLOPEN:
|
||||
return urllib.request.urlopen(req, timeout=timeout)
|
||||
if not any(name.lower() in _CREDENTIAL_REDIRECT_HEADERS for name, _ in req.header_items()):
|
||||
return urllib.request.urlopen(req, timeout=timeout)
|
||||
original_host = (urllib.parse.urlparse(req.full_url).hostname or "").lower()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue