MCPcopy Create free account
hub / github.com/masterking32/MasterHttpRelayVPN / cors_preflight_response

Function cors_preflight_response

src/proxy/proxy_support.py:264–287  ·  view source on GitHub ↗

Build a 204 response that satisfies a CORS preflight locally. Apps Script's UrlFetchApp does not support OPTIONS, so preflights must be answered here rather than forwarded to the relay.

(origin: str, acr_method: str, acr_headers: str)

Source from the content-addressed store, hash-verified

262# ── CORS helpers ──────────────────────────────────────────────────────────────
263
264def cors_preflight_response(origin: str, acr_method: str, acr_headers: str) -> bytes:
265 """Build a 204 response that satisfies a CORS preflight locally.
266
267 Apps Script's UrlFetchApp does not support OPTIONS, so preflights must
268 be answered here rather than forwarded to the relay.
269 """
270 allow_origin = origin or "*"
271 allow_methods = (
272 f"{acr_method}, GET, POST, PUT, DELETE, PATCH, OPTIONS"
273 if acr_method else
274 "GET, POST, PUT, DELETE, PATCH, OPTIONS"
275 )
276 allow_headers = acr_headers or "*"
277 return (
278 "HTTP/1.1 204 No Content\r\n"
279 f"Access-Control-Allow-Origin: {allow_origin}\r\n"
280 f"Access-Control-Allow-Methods: {allow_methods}\r\n"
281 f"Access-Control-Allow-Headers: {allow_headers}\r\n"
282 "Access-Control-Allow-Credentials: true\r\n"
283 "Access-Control-Max-Age: 86400\r\n"
284 "Vary: Origin\r\n"
285 "Content-Length: 0\r\n"
286 "\r\n"
287 ).encode()
288
289
290def inject_cors_headers(response: bytes, origin: str) -> bytes:

Callers 2

_relay_http_streamMethod · 0.85
_do_httpMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected