parseRawURL extracts scheme, host, and raw path from a URI without decoding percent-encoded sequences. This allows non-standard encodings like %u002f (IIS-style Unicode escapes) to be sent to the server as-is.
(rawURI string)
| 401 | // percent-encoded sequences. This allows non-standard encodings like %u002f |
| 402 | // (IIS-style Unicode escapes) to be sent to the server as-is. |
| 403 | func parseRawURL(rawURI string) (*url.URL, error) { |
| 404 | idx := strings.Index(rawURI, "://") |
| 405 | if idx < 0 { |
| 406 | return nil, fmt.Errorf("missing scheme") |
| 407 | } |
| 408 | scheme := rawURI[:idx] |
| 409 | if scheme != "http" && scheme != "https" { |
| 410 | return nil, fmt.Errorf("unsupported scheme %q", scheme) |
| 411 | } |
| 412 | rest := rawURI[idx+3:] |
| 413 | |
| 414 | slashIdx := strings.Index(rest, "/") |
| 415 | var host, rawPath string |
| 416 | if slashIdx < 0 { |
| 417 | host = rest |
| 418 | rawPath = "/" |
| 419 | } else { |
| 420 | host = rest[:slashIdx] |
| 421 | rawPath = rest[slashIdx:] |
| 422 | } |
| 423 | |
| 424 | if host == "" { |
| 425 | return nil, fmt.Errorf("missing host") |
| 426 | } |
| 427 | |
| 428 | // Split raw path and query |
| 429 | rawQuery := "" |
| 430 | if qIdx := strings.Index(rawPath, "?"); qIdx >= 0 { |
| 431 | rawQuery = rawPath[qIdx+1:] |
| 432 | rawPath = rawPath[:qIdx] |
| 433 | } |
| 434 | |
| 435 | return &url.URL{ |
| 436 | Scheme: scheme, |
| 437 | Host: host, |
| 438 | Opaque: rawPath, |
| 439 | RawQuery: rawQuery, |
| 440 | }, nil |
| 441 | } |
| 442 | |
| 443 | func rawRequestTarget(rawURI string) string { |
| 444 | idx := strings.Index(rawURI, "://") |
no outgoing calls
no test coverage detected