aboutsummaryrefslogtreecommitdiff
path: root/http_test.go
diff options
context:
space:
mode:
authorGravatar Tolyar <Tolyar@users.noreply.github.com> 2021-12-17 08:26:17 +0300
committerGravatar GitHub <noreply@github.com> 2021-12-17 06:26:17 +0100
commit4517204499caef79d5a956cc816e5f0903f0ff6d (patch)
tree4b499dcf745d6492269ae9ac407786ec531e3705 /http_test.go
parentfix: reset response after reset user values on keep-alive connections (#1176) (diff)
downloadfasthttp-4517204499caef79d5a956cc816e5f0903f0ff6d.tar.gz
fasthttp-4517204499caef79d5a956cc816e5f0903f0ff6d.tar.bz2
fasthttp-4517204499caef79d5a956cc816e5f0903f0ff6d.zip
Allow to set Host header for Client (#1169)
* Allow to set Host header for Client * Allow to change Host header without tests violation * Rename AllowToChangeHostHeader and add tests. * Allow to use empty uri.Host() when req.Header.Host() does not empty
Diffstat (limited to 'http_test.go')
-rw-r--r--http_test.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/http_test.go b/http_test.go
index a4a1e58..ac71903 100644
--- a/http_test.go
+++ b/http_test.go
@@ -79,7 +79,7 @@ func TestIssue875(t *testing.T) {
expectedLocation string
}
- var testcases = []testcase{
+ testcases := []testcase{
{
uri: `http://localhost:3000/?redirect=foo%0d%0aSet-Cookie:%20SESSIONID=MaliciousValue%0d%0a`,
expectedRedirect: "foo\r\nSet-Cookie: SESSIONID=MaliciousValue\r\n",
@@ -138,7 +138,6 @@ func TestRequestCopyTo(t *testing.T) {
t.Fatalf("unexpected error: %s", err)
}
testRequestCopyTo(t, &req)
-
}
func TestResponseCopyTo(t *testing.T) {
@@ -155,7 +154,6 @@ func TestResponseCopyTo(t *testing.T) {
resp.Header.SetStatusCode(200)
resp.SetBodyString("test")
testResponseCopyTo(t, &resp)
-
}
func testRequestCopyTo(t *testing.T, src *Request) {
@@ -731,6 +729,31 @@ func TestRequestUpdateURI(t *testing.T) {
}
}
+func TestUseHostHeader(t *testing.T) {
+ t.Parallel()
+
+ var r Request
+ r.UseHostHeader = true
+ r.Header.SetHost("aaa.bbb")
+ r.SetRequestURI("/lkjkl/kjl")
+
+ // Modify request uri and host via URI() object and make sure
+ // the requestURI and Host header are properly updated
+ u := r.URI()
+ u.SetPath("/123/432.html")
+ u.SetHost("foobar.com")
+ a := u.QueryArgs()
+ a.Set("aaa", "bcse")
+
+ s := r.String()
+ if !strings.HasPrefix(s, "GET /123/432.html?aaa=bcse") {
+ t.Fatalf("cannot find %q in %q", "GET /123/432.html?aaa=bcse", s)
+ }
+ if !strings.Contains(s, "\r\nHost: aaa.bbb\r\n") {
+ t.Fatalf("cannot find %q in %q", "\r\nHost: aaa.bbb\r\n", s)
+ }
+}
+
func TestRequestBodyStreamMultipleBodyCalls(t *testing.T) {
t.Parallel()
@@ -1190,7 +1213,6 @@ func TestRequestContinueReadBodyDisablePrereadMultipartForm(t *testing.T) {
if string(formData) != string(r.Body()) {
t.Fatalf("The body given must equal the body in the Request")
}
-
}
func TestRequestMayContinue(t *testing.T) {
@@ -2434,7 +2456,6 @@ Content-Type: application/json
`, "\n", "\r\n", -1)
mr := multipart.NewReader(strings.NewReader(s), "foo")
form, err := mr.ReadForm(1024)
-
if err != nil {
t.Fatalf("unexpected error: %s", err)
}