(url)
| 94 | |
| 95 | const parseUrl_regex = /^(?:(https?):\/\/)?([^/:]+)?(?::(\d+))?(\/.*)?$/i; |
| 96 | export const parseUrl = function (url): ParsedUrl | undefined { |
| 97 | //there are many correct ways to parse a URL, |
| 98 | //however, a mitmproxy user may also wish to generate a not-so-correct URL. ;-) |
| 99 | const parts = parseUrl_regex.exec(url); |
| 100 | if (!parts) { |
| 101 | return undefined; |
| 102 | } |
| 103 | |
| 104 | const scheme = parts[1]; |
| 105 | const host = parts[2]; |
| 106 | const optionalPort = parseInt(parts[3]); |
| 107 | const path = parts[4]; |
| 108 | const port = scheme ? optionalPort || defaultPorts[scheme] : optionalPort; |
| 109 | const ret: ParsedUrl = {}; |
| 110 | if (scheme) { |
| 111 | ret.scheme = scheme; |
| 112 | } |
| 113 | if (host) { |
| 114 | ret.host = host; |
| 115 | } |
| 116 | if (port) { |
| 117 | ret.port = port; |
| 118 | } |
| 119 | if (path) { |
| 120 | ret.path = path; |
| 121 | } |
| 122 | return ret; |
| 123 | }; |
| 124 | |
| 125 | const isValidHttpVersion_regex = /^HTTP\/\d+(\.\d+)*$/i; |
| 126 | export const isValidHttpVersion = function (httpVersion: string): boolean { |
no test coverage detected
searching dependent graphs…