Skip to content

proposal: net/http: allow setting timeouts individually in Client #23100

Closed
@alex-leonhardt

Description

@alex-leonhardt

What version of Go are you using (go version)?

go1.9 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ale/projects/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/c6/5xqsbcl95j713z7y5tz1cp6m0000gn/T/go-build047959207=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

It's not a bug; more a feature request. When calling a HTTP endpoint using http.Client; it'd be great if it was possible to individually configure the connection timeout from the response timeout and a generic timeout that would count for both. Reason I'm asking for this is to be able to fail fast when a endpoint just isn't there, vs wait for potentially longer when there is a endpoint and it's slow to respond. I've found some implementation of this, but it is much more "work" than it really should be.

https://stackoverflow.com/questions/16895294/how-to-set-timeout-for-http-get-requests-in-golang

Cloudflare's blog is pretty good, and much more concise, however, still more than I would have expected : https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/

What did you expect to see?

http.Client{
  ConnectionTimeout: time.Duration,
  ResponseTimeout: time.Duration
}

What did you see instead?

http.Client{
  Timeout: time.Duration
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Proposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions