How to implement guide with go's http client timing out on redirects with custom headers
I'm converting an old project and I'm working with a frustrating scenario when using Go's `http.Client` to make requests that involve redirects. I have a scenario where I need to send custom headers when following redirects, but it seems that my client times out before it can complete the redirect process. The scenario arises particularly when the redirect target is down or slow to respond. I'm using Go version 1.19.2, and hereβs a simplified version of my code: ```go package main import ( "fmt" "net/http" "time" ) func main() { client := &http.Client{ Timeout: 5 * time.Second, } req, err := http.NewRequest("GET", "http://example.com/redirect", nil) if err != nil { fmt.Println("behavior creating request:", err) return } req.Header.Set("Custom-Header", "value") resp, err := client.Do(req) if err != nil { fmt.Println("behavior making request:", err) return } defer resp.Body.Close() fmt.Println("Response status:", resp.Status) } ``` When I run this code, if the redirect target is slow or unresponsive, I get an behavior like `Get "http://example.com/redirect": context deadline exceeded`. I've tried increasing the timeout to 10 seconds, but it still times out in the same scenarios. I suspect that the custom headers might be causing issues during the redirect handling, but Iβm not sure how to debug this effectively. What am I doing wrong, and how can I ensure that my `http.Client` handles the redirects while still sending the custom headers? Is there a way to control the redirect behavior to avoid timeouts in these situations? I'm coming from a different tech stack and learning Go.