MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / parseUrl

Function parseUrl

web/src/js/flow/utils.ts:96–123  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

94
95const parseUrl_regex = /^(?:(https?):\/\/)?([^/:]+)?(?::(\d+))?(\/.*)?$/i;
96export 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
125const isValidHttpVersion_regex = /^HTTP\/\d+(\.\d+)*$/i;
126export const isValidHttpVersion = function (httpVersion: string): boolean {

Callers 1

RequestLineFunction · 0.90

Calls 1

execMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…