syshttp.autopatch
syshttp.autopatch
Patch HTTP client libraries as they are imported, so they route and verify
the way syshttp does: routing by :func:syshttp.proxy.proxy_map through
proxylib's client integrations (proxylib.patch), and TLS by the system's
context (:func:syshttp.tls.os_ssl_context).
SYSHTTP_IMPORTPATCH chooses the libraries -- read under the prefixes as
every setting is (SYSHTTP_PREFIX=AGENTS_: AGENTS_SYSHTTP_IMPORTPATCH): 1/true/yes/on for all of
:data:TARGETS, 0/false/no/off, empty or unset for none, else
their names separated by : (requests:httpx; a module name such as
urllib.request works too). It is read when the library is imported:
importpatch (a dependency) calls :func:importpatch for each target, through
this distribution's importpatch entry points. :func:patch applies the
same patches from code, whatever the setting says.
What the caller chose always wins: a proxy given to the client, a context, a
CA bundle or verify=False.
enabled(*, env=None)
The names of :data:TARGETS that :func:setting_name enables, :
separated. A name that is not a target is logged at WARNING and skipped.
Source code in src/syshttp/autopatch.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
importpatch(name, module)
importpatch's entry point: patch module, just imported as name,
when :func:setting_name enables it.
Source code in src/syshttp/autopatch.py
89 90 91 92 93 94 95 | |
patch(targets=None)
Patch targets now (default: every target whose library is
installed), importing each library. A name that is not a target is a
ValueError; a named library that is not installed raises its
ImportError. Returns the names patched; patching twice does nothing.
Source code in src/syshttp/autopatch.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
patched()
The names patched now, in the order applied.
Source code in src/syshttp/autopatch.py
131 132 133 134 | |
setting_name(*, env=None)
The variable that chooses the libraries: <PREFIX>SYSHTTP_IMPORTPATCH
for the first prefix that sets it (AGENTS_SYSHTTP_IMPORTPATCH under
SYSHTTP_PREFIX=AGENTS_), else the name under the first prefix.
Source code in src/syshttp/autopatch.py
57 58 59 60 61 62 63 | |
unpatch()
Undo every patch, the last applied first. A client built while patched keeps what it was given; proxylib's integrations stay installed, back on proxylib's default map.
Source code in src/syshttp/autopatch.py
121 122 123 124 125 126 127 128 | |