lancet icon indicating copy to clipboard operation
lancet copied to clipboard

HTTP methods do not have a way to set a timeout

Open dobegor opened this issue 2 years ago • 1 comments

Functions that make HTTP requests should accept context for cancellation. Even worse, an http client with default options is used. Not only it doesn't have any timeouts, creating a new HTTP client for every single request isn't efficient and would not utilise HTTP "keep alive" mechanics.

dobegor avatar Jul 21 '22 14:07 dobegor

Functions that make HTTP requests should accept context for cancellation. Even worse, an http client with default options is used. Not only it doesn't have any timeouts, creating a new HTTP client for every single request isn't efficient and would not utilise HTTP "keep alive" mechanics.

@dobegor : Yeah, your point makes sense. I do have plan to refactor the http request functions in file netutil/http.go. Here is the solution:

  1. Add context param to exists functions(HttpGet, HttpPost, HttpPut, HttpDelete, HttpPatch). This will bring break changes compare to previous version.
  2. Create new function and redesign the logic of http request. Will support for common features. Eg. Timeout...

I prefer the second one.

duke-git avatar Jul 22 '22 08:07 duke-git

Functions that make HTTP requests should accept context for cancellation. Even worse, an http client with default options is used. Not only it doesn't have any timeouts, creating a new HTTP client for every single request isn't efficient and would not utilise HTTP "keep alive" mechanics.

Redesign the logic of sending http request, refer to - http_client.go.

duke-git avatar Aug 31 '22 09:08 duke-git