Skip to content

Feature request: have http.request() accept socket timeout option which is passed to http.Agent and applied BEFORE connecting #7580

@rogierschouten

Description

@rogierschouten
  • Version: v6.2.2
  • Platform: Windows 7 64-bit
  • Subsystem:

For plain socket ('net' module) it is possible to set the socket connect timeout by using socket#setTimeout() before calling socket#connect(). On windows, this has effect as long as you keep the timeout below 20 seconds (which is the Windows default TCP connect timeout). E.g. setting 1 second and then connecting to a non-existing IP address will give a timeout after 1 second, but setting 25 seconds will still timeout after 20 seconds.

For the http module, there is no such option (http.request() does not take a timeout). There are no workarounds: using ClientRequest#setTimeout() or catching the socket in the on('socket') event and using socket#setTimeout both result in the timeout being set after the connect() call, so it does not function as a connect timeout.

So the request is to adjust http.request() function so that it takes a timeout option which is set on the socket before it connects. This will in turn require passing on the timeout to the http.Agent#createConnection() when requesting a connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions