node-modules / urllib

Request HTTP(s) URLs in a complex world.
MIT License
727 stars 117 forks source link

Invalid request to relative url after 514de1924bf17a38a6c2db2a22a6bc3494c0a959 #348

Closed konovalovsergey closed 2 years ago

konovalovsergey commented 3 years ago

Relative url to http.request leads to invalid request For example http.request('/foo.bar') https://github.com/node-modules/urllib/blob/dbfcd6ef01cd925beeef1f80fabe0edd259d6aac/lib/urllib.js#L232

parsedUrl = {
  "protocol": "http:",
  "slashes": true,
  "auth": null,
  "host": "foo.bar",
  "port": null,
  "hostname": "foo.bar",
  "hash": null,
  "search": null,
  "query": null,
  "pathname": "/",
  "path": "/",
  "href": "http://foo.bar/"
}

request is sent to http://foo.bar:80 before 514de1924bf17a38a6c2db2a22a6bc3494c0a959 it was

parsedUrl = {
  "protocol": "http:",
  "slashes": true,
  "auth": null,
  "host": "",
  "port": null,
  "hostname": "",
  "hash": null,
  "search": null,
  "query": null,
  "pathname": "/foo.bar",
  "path": "/foo.bar",
  "href": "http:///foo.bar"
}

request is sent to http://localhost:80/foo.bar