MCPcopy Create free account
hub / github.com/vercel/vercel / split_request_target

Function split_request_target

python/vercel-runtime/src/vercel_runtime/routing.py:49–78  ·  view source on GitHub ↗

Split an HTTP request-target into (path, query). Supports: - origin-form: "/a/b?x=1" - absolute-form: "https://example.com/a/b?x=1" - asterisk-form: "*"

(target: str)

Source from the content-addressed store, hash-verified

47
48
49def split_request_target(target: str) -> tuple[str, str]:
50 """
51 Split an HTTP request-target into (path, query).
52
53 Supports:
54 - origin-form: "/a/b?x=1"
55 - absolute-form: "https://example.com/a/b?x=1"
56 - asterisk-form: "*"
57 """
58 if not target:
59 return "/", ""
60
61 parsed = urlsplit(target)
62 path = parsed.path
63 query = parsed.query
64
65 # Absolute-form request-target (RFC 7230 section 5.3.2).
66 if parsed.scheme in ("http", "https") and parsed.netloc:
67 return path or "/", query
68
69 # Asterisk-form request-target (RFC 7230 section 5.3.4).
70 if path == "*":
71 return "*", query
72
73 if not path:
74 path = "/"
75 elif not path.startswith("/"):
76 path = f"/{path}"
77
78 return path, query
79
80
81def strip_service_route_prefix(

Callers 4

handle_one_requestMethod · 0.90
handle_requestMethod · 0.90
vc_handlerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected