Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UseHostHeader for DoTimeout + tests #1184

Merged
merged 1 commit into from Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions http.go
Expand Up @@ -732,6 +732,8 @@ func (req *Request) copyToSkipBody(dst *Request) {
dst.parsedPostArgs = req.parsedPostArgs
dst.isTLS = req.isTLS

dst.UseHostHeader = req.UseHostHeader

// do not copy multipartForm - it will be automatically
// re-created on the first call to MultipartForm.
}
Expand Down
37 changes: 37 additions & 0 deletions http_test.go
Expand Up @@ -9,6 +9,8 @@ import (
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httptest"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -754,6 +756,41 @@ func TestUseHostHeader(t *testing.T) {
}
}

func TestUseHostHeader2(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Host != "SomeHost" {
http.Error(w, fmt.Sprintf("Expected Host header to be '%s', but got '%s'", "SomeHost", r.Host), http.StatusBadRequest)
} else {
w.WriteHeader(http.StatusOK)
}
}))
defer testServer.Close()

client := &Client{}
req := AcquireRequest()
defer ReleaseRequest(req)
resp := AcquireResponse()
defer ReleaseResponse(resp)

req.SetRequestURI(testServer.URL)
req.UseHostHeader = true
req.Header.SetHost("SomeHost")
if err := client.DoTimeout(req, resp, 1*time.Second); err != nil {
t.Fatalf("DoTimeout returned an error '%s'", err)
} else {
if resp.StatusCode() != http.StatusOK {
t.Fatalf("DoTimeout: %s", resp.body)
}
}
if err := client.Do(req, resp); err != nil {
t.Fatalf("DoTimeout returned an error '%s'", err)
} else {
if resp.StatusCode() != http.StatusOK {
t.Fatalf("Do: %s", resp.body)
}
}
}

func TestRequestBodyStreamMultipleBodyCalls(t *testing.T) {
t.Parallel()

Expand Down