diff options
author | Shivansh Vij <shivanshvij@loopholelabs.io> | 2021-11-08 00:44:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-08 09:44:02 +0100 |
commit | 2ca01c7efb6dcd2d75b36571c857847b9a1b2592 (patch) | |
tree | 2c8c8013bb8a59500e1e78b0f75869a48111705d /header_test.go | |
parent | Fix lint (diff) | |
download | fasthttp-2ca01c7efb6dcd2d75b36571c857847b9a1b2592.tar.gz fasthttp-2ca01c7efb6dcd2d75b36571c857847b9a1b2592.tar.bz2 fasthttp-2ca01c7efb6dcd2d75b36571c857847b9a1b2592.zip |
fix: Status Line parsing and writing (#1135)
* Adding zero-allocation uint64 to byte slice conversion and fixing the ResponseHeader.SetStatusLine function call signature
* Removing unnecessary i2b function
* Fixing various bugs
* Adding test cases
* Commenting AppendStatusLine
* Update status.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* Update header.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* Cleaning up references to strHTTP11, using formatStatusLine for invalidStatusLine, and making `appendStatusLine` an unexported function
Issue: https://github.com/valyala/fasthttp/issues/1132
* Fixing merge conflicts
Issue: https://github.com/valyala/fasthttp/issues/1132
* Replacing []byte{} with nil in some test cases
Issue: https://github.com/valyala/fasthttp/issues/1132
* Cleaning up parsing first line, and improving StatusMessage function
Issue: https://github.com/valyala/fasthttp/issues/1132
* Fixing as per PR
* Update header.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* Update header.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* Fixing as per requested changes
* Update header_test.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
Diffstat (limited to 'header_test.go')
-rw-r--r-- | header_test.go | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/header_test.go b/header_test.go index 19138ad..27a292c 100644 --- a/header_test.go +++ b/header_test.go @@ -52,8 +52,29 @@ func TestResponseHeaderMultiLineValue(t *testing.T) { t.Fatalf("parse response using net/http failed, %s", err) } - if !bytes.Equal(header.StatusLine(), []byte("SuperOK")) { - t.Errorf("parse status line with non-default value failed, got: %s want: SuperOK", header.StatusLine()) + if !bytes.Equal(header.StatusMessage(), []byte("SuperOK")) { + t.Errorf("parse status line with non-default value failed, got: '%s' want: 'SuperOK'", header.StatusMessage()) + } + + header.SetProtocol([]byte("HTTP/3.3")) + if !bytes.Equal(header.Protocol(), []byte("HTTP/3.3")) { + t.Errorf("parse protocol with non-default value failed, got: '%s' want: 'HTTP/3.3'", header.Protocol()) + } + + if !bytes.Equal(header.appendStatusLine(nil), []byte("HTTP/3.3 200 SuperOK\r\n")) { + t.Errorf("parse status line with non-default value failed, got: '%s' want: 'HTTP/3.3 200 SuperOK'", header.Protocol()) + } + + header.SetStatusMessage(nil) + + if !bytes.Equal(header.appendStatusLine(nil), []byte("HTTP/3.3 200 OK\r\n")) { + t.Errorf("parse status line with default protocol value failed, got: '%s' want: 'HTTP/3.3 200 OK'", header.appendStatusLine(nil)) + } + + header.SetStatusMessage(s2b(StatusMessage(200))) + + if !bytes.Equal(header.appendStatusLine(nil), []byte("HTTP/3.3 200 OK\r\n")) { + t.Errorf("parse status line with default protocol value failed, got: '%s' want: 'HTTP/3.3 200 OK'", header.appendStatusLine(nil)) } for name, vals := range response.Header { @@ -83,8 +104,16 @@ func TestResponseHeaderMultiLineName(t *testing.T) { t.Errorf("expected error, got %q (%v)", m, err) } - if !bytes.Equal(header.StatusLine(), []byte("OK")) { - t.Errorf("expected default status line, got: %s", header.StatusLine()) + if !bytes.Equal(header.StatusMessage(), []byte("OK")) { + t.Errorf("expected default status line, got: %s", header.StatusMessage()) + } + + if !bytes.Equal(header.Protocol(), []byte("HTTP/1.1")) { + t.Errorf("expected default protocol, got: %s", header.Protocol()) + } + + if !bytes.Equal(header.appendStatusLine(nil), []byte("HTTP/1.1 200 OK\r\n")) { + t.Errorf("parse status line with non-default value failed, got: %s want: HTTP/1.1 200 OK", header.Protocol()) } } |