* @param {string} aUrl The request URL to parse. * @return {RequestOptions} The request options. * @throws {Error} if the URL does not include a hostname.
(aUrl)
| 45 | * @throws {Error} if the URL does not include a hostname. |
| 46 | */ |
| 47 | function getRequestOptions(aUrl) { |
| 48 | // eslint-disable-next-line n/no-deprecated-api |
| 49 | let options = url.parse(aUrl) |
| 50 | if (!options.hostname) { |
| 51 | throw new Error('Invalid URL: ' + aUrl) |
| 52 | } |
| 53 | // Delete the search and has portions as they are not used. |
| 54 | options.search = null |
| 55 | options.hash = null |
| 56 | options.path = options.pathname |
| 57 | options.hostname = options.hostname === 'localhost' ? '127.0.0.1' : options.hostname // To support Node 17 and above. Refer https://github.com/nodejs/node/issues/40702 for details. |
| 58 | return options |
| 59 | } |
| 60 | |
| 61 | /** @const {string} */ |
| 62 | const USER_AGENT = (function () { |