Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Leonid Bugaev
2017-07-20 21:10:05 +03:00
2 changed files with 18 additions and 4 deletions
+6 -4
View File
@@ -346,12 +346,14 @@ func Path(payload []byte) []byte {
eol := bytes.IndexByte(payload[start:], '\r')
end := bytes.IndexByte(payload[start:], ' ')
if eol > 0 && eol < end {
return payload[start : start + eol]
} else if eol == - 1 { // support for legacy clients with wrong end of lines
if eol > 0 {
if end == -1 || eol < end {
return payload[start : start + eol]
}
} else { // support for legacy clients
eol = bytes.IndexByte(payload[start:], '\n')
if eol > 0 && eol < end {
if eol > 0 && (end == - 1 || eol < end) {
return payload[start : start + eol]
}
}
+12
View File
@@ -243,6 +243,18 @@ func TestPath(t *testing.T) {
if path = Path(payload); !bytes.Equal(path, []byte("/get")) {
t.Error("Should find path", string(path))
}
payload = []byte("GET /get\n")
if path = Path(payload); !bytes.Equal(path, []byte("/get")) {
t.Error("Should find path", string(path))
}
payload = []byte("GET /get")
if path = Path(payload); !bytes.Equal(path, []byte("/get")) {
t.Error("Should find path", string(path))
}
}
func TestSetPath(t *testing.T) {