mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Add support for binary input/output
This commit is contained in:
+14
-4
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/buger/gor/proto"
|
||||
raw "github.com/buger/gor/raw_socket_listener"
|
||||
"github.com/buger/gor-pro/proto"
|
||||
raw "github.com/buger/gor-pro/raw_socket_listener"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
@@ -18,6 +18,7 @@ type RAWInput struct {
|
||||
realIPHeader []byte
|
||||
trackResponse bool
|
||||
listener *raw.Listener
|
||||
protocol raw.TCPProtocol
|
||||
}
|
||||
|
||||
// Available engines for intercepting traffic
|
||||
@@ -28,7 +29,7 @@ const (
|
||||
)
|
||||
|
||||
// NewRAWInput constructor for RAWInput. Accepts address with port as argument.
|
||||
func NewRAWInput(address string, engine int, trackResponse bool, expire time.Duration, realIPHeader string) (i *RAWInput) {
|
||||
func NewRAWInput(address string, engine int, trackResponse bool, expire time.Duration, realIPHeader string, protocol string) (i *RAWInput) {
|
||||
i = new(RAWInput)
|
||||
i.data = make(chan *raw.TCPMessage)
|
||||
i.address = address
|
||||
@@ -38,6 +39,15 @@ func NewRAWInput(address string, engine int, trackResponse bool, expire time.Dur
|
||||
i.quit = make(chan bool)
|
||||
i.trackResponse = trackResponse
|
||||
|
||||
switch protocol {
|
||||
case "http":
|
||||
i.protocol = raw.ProtocolHTTP
|
||||
case "binary":
|
||||
i.protocol = raw.ProtocolBinary
|
||||
default:
|
||||
log.Fatal("Unsupported protocol:", protocol)
|
||||
}
|
||||
|
||||
i.listen(address)
|
||||
i.listener.IsReady()
|
||||
|
||||
@@ -80,7 +90,7 @@ func (i *RAWInput) listen(address string) {
|
||||
log.Fatal("input-raw: error while parsing address", err)
|
||||
}
|
||||
|
||||
i.listener = raw.NewListener(host, port, i.engine, i.trackResponse, i.expire)
|
||||
i.listener = raw.NewListener(host, port, i.engine, i.trackResponse, i.expire, i.protocol)
|
||||
|
||||
ch := i.listener.Receiver()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user