(url: string)
| 204 | } |
| 205 | |
| 206 | export function parseHostAndPath(url: string) { |
| 207 | try { |
| 208 | const urlObj = new URL(url); |
| 209 | const path = urlObj.pathname || '/'; |
| 210 | return { host: urlObj.host, path }; |
| 211 | } catch (_e) { |
| 212 | // If the URL was invalid do our best to parse the URL. |
| 213 | // Check for the protocol part and pull it off to grab the host |
| 214 | const splitted = url.split('//'); |
| 215 | const fullUrl = splitted[1] ? splitted[1] : url; |
| 216 | |
| 217 | // separate paths from the first element (host) |
| 218 | const parts = fullUrl.split('/'); |
| 219 | // pull off the host (mutates) |
| 220 | const host = parts.shift(); |
| 221 | // add a leading slash and join the paths again |
| 222 | const path = `/${parts.join('/')}`; |
| 223 | |
| 224 | return { host, path }; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // Body Generators |
| 229 | const BodyGenerators = { |
no outgoing calls
no test coverage detected