Skip to content

Commit

Permalink
Fix UseHostHeader for DoTimeout + tests (#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolyar committed Dec 26, 2021
1 parent 6b55811 commit 6c0518b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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

0 comments on commit 6c0518b

Please sign in to comment.