Add support for HTTP 1.0 and less

This commit is contained in:
Leonid Bugaev
2017-06-27 14:24:43 +02:00
parent 2680ce9dd4
commit 03767d1a77
2 changed files with 13 additions and 6 deletions
+3 -2
View File
@@ -343,10 +343,11 @@ func Body(payload []byte) []byte {
// Path takes payload and retuns request path: Split(firstLine, ' ')[1]
func Path(payload []byte) []byte {
start := bytes.IndexByte(payload, ' ') + 1
eol := bytes.IndexByte(payload[start:], '\r')
end := bytes.IndexByte(payload[start:], ' ')
if len(payload) < start + end {
return []byte{}
if eol < end {
return payload[start : start + eol]
}
return payload[start : start+end]
+10 -4
View File
@@ -65,13 +65,13 @@ func TestHeader(t *testing.T) {
}
func TestMIMEHeadersEndPos(t *testing.T) {
head := []byte("POST /post HTTP/1.1\r\nContent-Length: 7\r\nHost: www.w3.org")
head := []byte("POST /post HTTP/1.1\r\nContent-Length: 7\r\nHost: www.w3.org\r\n\r\n")
payload := []byte("POST /post HTTP/1.1\r\nContent-Length: 7\r\nHost: www.w3.org\r\n\r\na=1&b=2")
end := MIMEHeadersEndPos(payload)
if !bytes.Equal(payload[:end], head) {
t.Error("Wrong headers end position:", end)
t.Error("Wrong headers end position:", end, head, payload[:end])
}
}
@@ -80,10 +80,10 @@ func TestMIMEHeadersStartPos(t *testing.T) {
payload := []byte("POST /post HTTP/1.1\r\nContent-Length: 7\r\nHost: www.w3.org\r\n\r\na=1&b=2")
start := MIMEHeadersStartPos(payload)
end := MIMEHeadersEndPos(payload)
end := MIMEHeadersEndPos(payload) - 4
if !bytes.Equal(payload[start:end], headers) {
t.Error("Wrong headers end position:", start, end)
t.Error("Wrong headers end position:", start, end, payload[start:end])
}
}
@@ -237,6 +237,12 @@ func TestPath(t *testing.T) {
if path = Path(payload); !bytes.Equal(path, []byte("/post")) {
t.Error("Should find path", string(path))
}
payload = []byte("GET /get\r\n\r\nHost: www.w3.org\r\n\r\n")
if path = Path(payload); !bytes.Equal(path, []byte("/get")) {
t.Error("Should find path", string(path))
}
}
func TestSetPath(t *testing.T) {