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)
| 47 | |
| 48 | |
| 49 | def 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 | |
| 81 | def strip_service_route_prefix( |
no outgoing calls
no test coverage detected