Skip to content

Commit

Permalink
Rebase goreplay master
Browse files Browse the repository at this point in the history
  • Loading branch information
davidFR committed Jan 20, 2021
1 parent 7b60730 commit 71d8435
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 2 additions & 3 deletions proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions proto/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 71d8435

Please sign in to comment.