MCPcopy Index your code
hub / github.com/masterking32/MasterHttpRelayVPN / _relay_request

Function _relay_request

apps_script/vps_exit_node.py:187–209  ·  view source on GitHub ↗

Perform the outbound HTTP/HTTPS request and return a relay-JSON dict.

(
    url: str, method: str, headers: dict[str, str], body: bytes
)

Source from the content-addressed store, hash-verified

185
186
187def _relay_request(
188 url: str, method: str, headers: dict[str, str], body: bytes
189) -> dict:
190 """Perform the outbound HTTP/HTTPS request and return a relay-JSON dict."""
191 request = urllib.request.Request(url, method=method, headers=headers)
192 if body:
193 request.data = body
194
195 try:
196 with _NO_REDIRECT_OPENER.open(request, timeout=_OUTBOUND_TIMEOUT) as resp:
197 data = resp.read(_MAX_RESPONSE_BODY)
198 return {
199 "s": resp.status,
200 "h": _collect_headers(resp.headers),
201 "b": base64.b64encode(data).decode(),
202 }
203 except urllib.error.HTTPError as exc:
204 data = exc.read(_MAX_RESPONSE_BODY) if exc.fp else b""
205 return {
206 "s": exc.code,
207 "h": _collect_headers(exc.headers) if exc.headers else {},
208 "b": base64.b64encode(data).decode(),
209 }
210
211
212# ---------------------------------------------------------------------------

Callers 1

do_POSTMethod · 0.85

Calls 1

_collect_headersFunction · 0.85

Tested by

no test coverage detected