diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2019-12-01 09:44:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-01 09:44:11 +0100 |
commit | 39dd1045bb1683951b6677f3b5ed1837dc7988ff (patch) | |
tree | 14805f0a3954a0ac1e983fa404ea031aa91f033c /header_test.go | |
parent | Custom LookupIPAddr function (#699) (diff) | |
download | fasthttp-39dd1045bb1683951b6677f3b5ed1837dc7988ff.tar.gz fasthttp-39dd1045bb1683951b6677f3b5ed1837dc7988ff.tar.bz2 fasthttp-39dd1045bb1683951b6677f3b5ed1837dc7988ff.zip |
Allow a body for GET requests (#703)
This means we can't skip parsing headers for GET requests anymore. This
can be seen as good as it also allows us to reject malformed GET
requests, something we didn't do before this. Performance also isn't
affect much:
benchmark old ns/op new ns/op delta
BenchmarkClientGetEndToEnd1Inmemory-16 640 641 +0.16%
BenchmarkClientGetEndToEnd10Inmemory-16 713 710 -0.42%
BenchmarkClientGetEndToEnd100Inmemory-16 732 749 +2.32%
BenchmarkClientGetEndToEnd1000Inmemory-16 759 774 +1.98%
BenchmarkClientGetEndToEnd10KInmemory-16 785 808 +2.93%
BenchmarkNetHTTPClientGetEndToEnd1Inmemory-16 5045 4954 -1.80%
BenchmarkNetHTTPClientGetEndToEnd10Inmemory-16 5806 6225 +7.22%
BenchmarkNetHTTPClientGetEndToEnd100Inmemory-16 7877 7998 +1.54%
BenchmarkNetHTTPClientGetEndToEnd1000Inmemory-16 16603 16559 -0.27%
Diffstat (limited to 'header_test.go')
-rw-r--r-- | header_test.go | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/header_test.go b/header_test.go index 2f1a564..3debd97 100644 --- a/header_test.go +++ b/header_test.go @@ -1971,7 +1971,7 @@ func TestRequestHeaderBufioPeek(t *testing.T) { if err := h.Read(br); err != nil { t.Fatalf("Unexpected error when reading request: %s", err) } - verifyRequestHeader(t, h, 0, "/", "foobar.com", "", "") + verifyRequestHeader(t, h, -2, "/", "foobar.com", "", "") verifyTrailer(t, br, "aaaa") } @@ -2167,21 +2167,21 @@ func TestRequestHeaderReadSuccess(t *testing.T) { // simple headers testRequestHeaderReadSuccess(t, h, "GET /foo/bar HTTP/1.1\r\nHost: google.com\r\n\r\n", - 0, "/foo/bar", "google.com", "", "", "") + -2, "/foo/bar", "google.com", "", "", "") if h.ConnectionClose() { t.Fatalf("unexpected connection: close header") } // simple headers with body testRequestHeaderReadSuccess(t, h, "GET /a/bar HTTP/1.1\r\nHost: gole.com\r\nconneCTION: close\r\n\r\nfoobar", - 0, "/a/bar", "gole.com", "", "", "foobar") + -2, "/a/bar", "gole.com", "", "", "foobar") if !h.ConnectionClose() { t.Fatalf("connection: close unset") } // ancient http protocol testRequestHeaderReadSuccess(t, h, "GET /bar HTTP/1.0\r\nHost: gole\r\n\r\npppp", - 0, "/bar", "gole", "", "", "pppp") + -2, "/bar", "gole", "", "", "pppp") if h.IsHTTP11() { t.Fatalf("ancient http protocol cannot be http/1.1") } @@ -2191,7 +2191,7 @@ func TestRequestHeaderReadSuccess(t *testing.T) { // ancient http protocol with 'Connection: keep-alive' header testRequestHeaderReadSuccess(t, h, "GET /aa HTTP/1.0\r\nHost: bb\r\nConnection: keep-alive\r\n\r\nxxx", - 0, "/aa", "bb", "", "", "xxx") + -2, "/aa", "bb", "", "", "xxx") if h.IsHTTP11() { t.Fatalf("ancient http protocol cannot be http/1.1") } @@ -2201,7 +2201,7 @@ func TestRequestHeaderReadSuccess(t *testing.T) { // complex headers with body testRequestHeaderReadSuccess(t, h, "GET /aabar HTTP/1.1\r\nAAA: bbb\r\nHost: ole.com\r\nAA: bb\r\n\r\nzzz", - 0, "/aabar", "ole.com", "", "", "zzz") + -2, "/aabar", "ole.com", "", "", "zzz") if !h.IsHTTP11() { t.Fatalf("expecting http/1.1 protocol") } @@ -2211,7 +2211,7 @@ func TestRequestHeaderReadSuccess(t *testing.T) { // lf instead of crlf testRequestHeaderReadSuccess(t, h, "GET /foo/bar HTTP/1.1\nHost: google.com\n\n", - 0, "/foo/bar", "google.com", "", "", "") + -2, "/foo/bar", "google.com", "", "", "") // post method testRequestHeaderReadSuccess(t, h, "POST /aaa?bbb HTTP/1.1\r\nHost: foobar.com\r\nContent-Length: 1235\r\nContent-Type: aaa\r\n\r\nabcdef", @@ -2219,11 +2219,11 @@ func TestRequestHeaderReadSuccess(t *testing.T) { // zero-length headers with mixed crlf and lf testRequestHeaderReadSuccess(t, h, "GET /a HTTP/1.1\nHost: aaa\r\nZero: \n: Zero-Value\n\r\nxccv", - 0, "/a", "aaa", "", "", "xccv") + -2, "/a", "aaa", "", "", "xccv") // no space after colon testRequestHeaderReadSuccess(t, h, "GET /a HTTP/1.1\nHost:aaaxd\n\nsdfds", - 0, "/a", "aaaxd", "", "", "sdfds") + -2, "/a", "aaaxd", "", "", "sdfds") // get with zero content-length testRequestHeaderReadSuccess(t, h, "GET /xxx HTTP/1.1\nHost: aaa.com\nContent-Length: 0\n\n", @@ -2231,19 +2231,19 @@ func TestRequestHeaderReadSuccess(t *testing.T) { // get with non-zero content-length testRequestHeaderReadSuccess(t, h, "GET /xxx HTTP/1.1\nHost: aaa.com\nContent-Length: 123\n\n", - 0, "/xxx", "aaa.com", "", "", "") + 123, "/xxx", "aaa.com", "", "", "") // invalid case testRequestHeaderReadSuccess(t, h, "GET /aaa HTTP/1.1\nhoST: bbb.com\n\naas", - 0, "/aaa", "bbb.com", "", "", "aas") + -2, "/aaa", "bbb.com", "", "", "aas") // referer testRequestHeaderReadSuccess(t, h, "GET /asdf HTTP/1.1\nHost: aaa.com\nReferer: bb.com\n\naaa", - 0, "/asdf", "aaa.com", "bb.com", "", "aaa") + -2, "/asdf", "aaa.com", "bb.com", "", "aaa") // duplicate host testRequestHeaderReadSuccess(t, h, "GET /aa HTTP/1.1\r\nHost: aaaaaa.com\r\nHost: bb.com\r\n\r\n", - 0, "/aa", "bb.com", "", "", "") + -2, "/aa", "bb.com", "", "", "") // post with duplicate content-type testRequestHeaderReadSuccess(t, h, "POST /a HTTP/1.1\r\nHost: aa\r\nContent-Type: ab\r\nContent-Length: 123\r\nContent-Type: xx\r\n\r\n", @@ -2255,39 +2255,39 @@ func TestRequestHeaderReadSuccess(t *testing.T) { // non-post with content-type testRequestHeaderReadSuccess(t, h, "GET /aaa HTTP/1.1\r\nHost: bbb.com\r\nContent-Type: aaab\r\n\r\n", - 0, "/aaa", "bbb.com", "", "aaab", "") + -2, "/aaa", "bbb.com", "", "aaab", "") // non-post with content-length testRequestHeaderReadSuccess(t, h, "HEAD / HTTP/1.1\r\nHost: aaa.com\r\nContent-Length: 123\r\n\r\n", - 0, "/", "aaa.com", "", "", "") + 123, "/", "aaa.com", "", "", "") // non-post with content-type and content-length testRequestHeaderReadSuccess(t, h, "GET /aa HTTP/1.1\r\nHost: aa.com\r\nContent-Type: abd/test\r\nContent-Length: 123\r\n\r\n", - 0, "/aa", "aa.com", "", "abd/test", "") + 123, "/aa", "aa.com", "", "abd/test", "") // request uri with hostname testRequestHeaderReadSuccess(t, h, "GET http://gooGle.com/foO/%20bar?xxx#aaa HTTP/1.1\r\nHost: aa.cOM\r\n\r\ntrail", - 0, "http://gooGle.com/foO/%20bar?xxx#aaa", "aa.cOM", "", "", "trail") + -2, "http://gooGle.com/foO/%20bar?xxx#aaa", "aa.cOM", "", "", "trail") // no protocol in the first line testRequestHeaderReadSuccess(t, h, "GET /foo/bar\r\nHost: google.com\r\n\r\nisdD", - 0, "/foo/bar", "google.com", "", "", "isdD") + -2, "/foo/bar", "google.com", "", "", "isdD") // blank lines before the first line testRequestHeaderReadSuccess(t, h, "\r\n\n\r\nGET /aaa HTTP/1.1\r\nHost: aaa.com\r\n\r\nsss", - 0, "/aaa", "aaa.com", "", "", "sss") + -2, "/aaa", "aaa.com", "", "", "sss") // request uri with spaces testRequestHeaderReadSuccess(t, h, "GET /foo/ bar baz HTTP/1.1\r\nHost: aa.com\r\n\r\nxxx", - 0, "/foo/ bar baz", "aa.com", "", "", "xxx") + -2, "/foo/ bar baz", "aa.com", "", "", "xxx") // no host testRequestHeaderReadSuccess(t, h, "GET /foo/bar HTTP/1.1\r\nFOObar: assdfd\r\n\r\naaa", - 0, "/foo/bar", "", "", "", "aaa") + -2, "/foo/bar", "", "", "", "aaa") // no host, no headers testRequestHeaderReadSuccess(t, h, "GET /foo/bar HTTP/1.1\r\n\r\nfoobar", - 0, "/foo/bar", "", "", "", "foobar") + -2, "/foo/bar", "", "", "", "foobar") // post without content-length and content-type testRequestHeaderReadSuccess(t, h, "POST /aaa HTTP/1.1\r\nHost: aaa.com\r\n\r\nzxc", @@ -2374,7 +2374,7 @@ func testRequestHeaderReadError(t *testing.T, h *RequestHeader, headers string) // make sure request header works after error testRequestHeaderReadSuccess(t, h, "GET /foo/bar HTTP/1.1\r\nHost: aaaa\r\n\r\nxxx", - 0, "/foo/bar", "aaaa", "", "", "xxx") + -2, "/foo/bar", "aaaa", "", "", "xxx") } func testResponseHeaderReadSuccess(t *testing.T, h *ResponseHeader, headers string, expectedStatusCode, expectedContentLength int, |