mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Add support for HTTP 1.0 and less
This commit is contained in:
+3
-2
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user