diff --git a/proto/proto.go b/proto/proto.go index 3bc63ed..8ca4cbb 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -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] } } diff --git a/proto/proto_test.go b/proto/proto_test.go index 4ff2dc5..210a9c1 100644 --- a/proto/proto_test.go +++ b/proto/proto_test.go @@ -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) {