Add support for binary input/output

This commit is contained in:
Leonid Bugaev
2016-07-13 16:01:25 +03:00
parent 12287d8bae
commit a6d263df1c
15 changed files with 494 additions and 84 deletions
+14 -4
View File
@@ -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()