mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Add support for tcp sessions
This commit is contained in:
+16
-4
@@ -9,6 +9,7 @@ import (
|
||||
// TestInput used for testing purpose, it allows emitting requests on demand
|
||||
type TestInput struct {
|
||||
data chan []byte
|
||||
disableHeaders bool
|
||||
}
|
||||
|
||||
// NewTestInput constructor for TestInput
|
||||
@@ -22,11 +23,21 @@ func NewTestInput() (i *TestInput) {
|
||||
func (i *TestInput) Read(data []byte) (int, error) {
|
||||
buf := <-i.data
|
||||
|
||||
header := payloadHeader(RequestPayload, uuid(), time.Now().UnixNano(), -1)
|
||||
copy(data[0:len(header)], header)
|
||||
copy(data[len(header):], buf)
|
||||
if !i.disableHeaders {
|
||||
header := payloadHeader(RequestPayload, uuid(), time.Now().UnixNano(), -1)
|
||||
copy(data[0:len(header)], header)
|
||||
copy(data[len(header):], buf)
|
||||
|
||||
return len(buf) + len(header), nil
|
||||
return len(buf) + len(header), nil
|
||||
} else {
|
||||
copy(data, buf)
|
||||
return len(buf), nil
|
||||
}
|
||||
}
|
||||
|
||||
// EmitGET emits GET request without headers
|
||||
func (i *TestInput) EmitBytes(b []byte) {
|
||||
i.data <- b
|
||||
}
|
||||
|
||||
// EmitGET emits GET request without headers
|
||||
@@ -34,6 +45,7 @@ func (i *TestInput) EmitGET() {
|
||||
i.data <- []byte("GET / HTTP/1.1\r\n\r\n")
|
||||
}
|
||||
|
||||
|
||||
// EmitPOST emits POST request with Content-Length
|
||||
func (i *TestInput) EmitPOST() {
|
||||
i.data <- []byte("POST /pub/WWW/ HTTP/1.1\r\nContent-Length: 7\r\nHost: www.w3.org\r\n\r\na=1&b=2")
|
||||
|
||||
Reference in New Issue
Block a user