Quantcast
Channel: How to set timeout for http.Get() requests in Golang? - Stack Overflow
Browsing latest articles
Browse All 8 View Live

Image may be NSFW.
Clik here to view.

Answer by zangw for How to set timeout for http.Get() requests in Golang?

There are several client-side timeouts in the Go http module, and there are some samples of those timeouts on current answers.Here is one image to illustrate the client-side timeout refer to The...

View Article



Answer by NoDataScientist for How to set timeout for http.Get() requests in...

timeout := time.Duration(5 * time.Second)transport := &http.Transport{Proxy: http.ProxyURL(proxyUrl), ResponseHeaderTimeout:timeout}This may help, but notice that ResponseHeaderTimeout starts only...

View Article

Answer by Chad Grant for How to set timeout for http.Get() requests in Golang?

If you want to do it per request, err handling ignored for brevity:ctx, cncl := context.WithTimeout(context.Background(), time.Second*3)defer cncl()req, _ := http.NewRequestWithContext(ctx,...

View Article

Answer by sparrovv for How to set timeout for http.Get() requests in Golang?

Apparently in Go 1.3 http.Client has Timeout fieldclient := http.Client{ Timeout: 5 * time.Second,}client.Get(url)That's done the trick for me.

View Article

Answer by dmichael for How to set timeout for http.Get() requests in Golang?

To add to Volker's answer, if you would also like to set the read/write timeout in addition to the connect timeout you can do something like the followingpackage httpclientimport...

View Article


Answer by Volker for How to set timeout for http.Get() requests in Golang?

You need to set up your own Client with your own Transport which uses acustom Dial function which wraps around DialTimeout.Something like (completely untested) this:var timeout = time.Duration(2 *...

View Article

Answer by zzzz for How to set timeout for http.Get() requests in Golang?

A quick and dirty way:http.DefaultTransport.(*http.Transport).ResponseHeaderTimeout = time.Second * 45This is mutating global state w/o any coordination. Yet it might be possibly okay for your url...

View Article

How to set timeout for http.Get() requests in Golang?

I'm making a URL fetcher in Go and have a list of URLs to fetch. I send http.Get() requests to each URL and obtain their response.resp,fetch_err := http.Get(url)How can I set a custom timeout for each...

View Article

Browsing latest articles
Browse All 8 View Live




Latest Images