From 71d8435b01a8b0e3eccd22bd7935e84514ba77ec Mon Sep 17 00:00:00 2001 From: David FRADIN Date: Wed, 20 Jan 2021 15:08:26 +0100 Subject: [PATCH] Rebase goreplay master --- proto/proto.go | 5 ++--- proto/proto_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/proto/proto.go b/proto/proto.go index e295fe6d7..d4b3847f2 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -307,8 +307,7 @@ func Method(payload []byte) []byte { } // Status returns response status. -// Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF -// Reason-Phrase is optional +// It happens to be in same position as request payload path func Status(payload []byte) []byte { if !HasResponseTitle(payload) { return nil @@ -352,7 +351,7 @@ func HasResponseTitle(payload []byte) bool { return false } status, ok := atoI(payload[VersionLen+1:VersionLen+4], 10) - if !ok || s[VersionLen+4] != ' ' { + if !ok { return false } // only validate status codes mentioned in rfc2616. diff --git a/proto/proto_test.go b/proto/proto_test.go index a0320c132..b37cbdc8a 100644 --- a/proto/proto_test.go +++ b/proto/proto_test.go @@ -136,6 +136,24 @@ func TestParseHeaders(t *testing.T) { if !reflect.DeepEqual(headers, expected) { t.Error("Headers do not properly parsed", headers) } + + // Response with Reason phrase + payload = [][]byte{[]byte("HTTP/1.1 200 OK\r\nContent-Length: 7\r\nHost: www.w3.org\r\nUser-Agent:Chrome\r\n\r\nbody")} + + headers = ParseHeaders(bytes.Join(payload, nil)) + + if !reflect.DeepEqual(headers, expected) { + t.Error("Headers do not properly parsed", headers) + } + + // Response without Reason phrase + payload = [][]byte{[]byte("HTTP/1.1 200\r\nContent-Length: 7\r\nHost: www.w3.org\r\nUser-Agent:Chrome\r\n\r\nbody")} + + headers = ParseHeaders(bytes.Join(payload, nil)) + + if !reflect.DeepEqual(headers, expected) { + t.Error("Headers do not properly parsed", headers) + } } // See https://github.com/dvyukov/go-fuzz and fuzz.go