mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Do not set http header if it explicitly set
This commit is contained in:
@@ -20,7 +20,7 @@ drace:
|
||||
docker run -v `pwd`:$(SOURCE_PATH) -t -i --env GORACE="halt_on_error=1" gor go test ./... $(ARGS) -v -race -timeout 15s
|
||||
|
||||
dtest:
|
||||
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go test ./... $(ARGS) -v -timeout 5s
|
||||
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go test ./... $(ARGS) -v -timeout 10s
|
||||
|
||||
dcover:
|
||||
docker run -v `pwd`:$(SOURCE_PATH) -t -i --env GORACE="halt_on_error=1" gor go test $(ARGS) -race -v -timeout 15s -coverprofile=coverage.out
|
||||
|
||||
+4
-1
@@ -20,6 +20,7 @@ var defaultPorts = map[string]string{
|
||||
type HTTPClientConfig struct {
|
||||
FollowRedirects int
|
||||
Debug bool
|
||||
OriginalHost bool
|
||||
}
|
||||
|
||||
type HTTPClient struct {
|
||||
@@ -115,7 +116,9 @@ func (c *HTTPClient) Send(data []byte) (response []byte, err error) {
|
||||
|
||||
c.conn.SetWriteDeadline(timeout)
|
||||
|
||||
data = proto.SetHost(data, []byte(c.baseURL), []byte(c.host))
|
||||
if !c.config.OriginalHost {
|
||||
data = proto.SetHost(data, []byte(c.baseURL), []byte(c.host))
|
||||
}
|
||||
|
||||
if c.config.Debug {
|
||||
Debug("[HTTPClient] Sending:", string(data))
|
||||
|
||||
@@ -21,7 +21,6 @@ type FileOutput struct {
|
||||
file *os.File
|
||||
}
|
||||
|
||||
|
||||
// NewFileOutput constructor for FileOutput, accepts path
|
||||
func NewFileOutput(path string) io.Writer {
|
||||
o := new(FileOutput)
|
||||
|
||||
@@ -18,6 +18,8 @@ type HTTPOutputConfig struct {
|
||||
|
||||
elasticSearch string
|
||||
|
||||
OriginalHost bool
|
||||
|
||||
Debug bool
|
||||
}
|
||||
|
||||
@@ -94,6 +96,7 @@ func (o *HTTPOutput) startWorker() {
|
||||
client := NewHTTPClient(o.address, &HTTPClientConfig{
|
||||
FollowRedirects: o.config.redirectLimit,
|
||||
Debug: o.config.Debug,
|
||||
OriginalHost: o.config.OriginalHost,
|
||||
})
|
||||
|
||||
deathCount := 0
|
||||
|
||||
@@ -76,6 +76,40 @@ func TestHTTPOutput(t *testing.T) {
|
||||
Settings.modifierConfig = HTTPModifierConfig{}
|
||||
}
|
||||
|
||||
func TestHTTPOutputKeepOriginalHost(t *testing.T) {
|
||||
wg := new(sync.WaitGroup)
|
||||
quit := make(chan int)
|
||||
|
||||
input := NewTestInput()
|
||||
|
||||
listener := startHTTP(func(req *http.Request) {
|
||||
if req.Host != "custom-host.com" {
|
||||
t.Error("Wrong header", req.Host)
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
})
|
||||
|
||||
headers := HTTPHeaders{HTTPHeader{"Host", "custom-host.com"}}
|
||||
Settings.modifierConfig = HTTPModifierConfig{headers: headers}
|
||||
|
||||
output := NewHTTPOutput(listener.Addr().String(), &HTTPOutputConfig{Debug: false, OriginalHost: true})
|
||||
|
||||
Plugins.Inputs = []io.Reader{input}
|
||||
Plugins.Outputs = []io.Writer{output}
|
||||
|
||||
go Start(quit)
|
||||
|
||||
wg.Add(1)
|
||||
input.EmitGET()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
close(quit)
|
||||
|
||||
Settings.modifierConfig = HTTPModifierConfig{}
|
||||
}
|
||||
|
||||
func TestOutputHTTPSSL(t *testing.T) {
|
||||
wg := new(sync.WaitGroup)
|
||||
quit := make(chan int)
|
||||
|
||||
@@ -98,6 +98,15 @@ func InitPlugins() {
|
||||
registerPlugin(NewHTTPInput, options)
|
||||
}
|
||||
|
||||
// If we explicitly set Host header http output should not rewrite it
|
||||
// Fix: https://github.com/buger/gor/issues/174
|
||||
for _, header := range Settings.modifierConfig.headers {
|
||||
if header.Name == "Host" {
|
||||
Settings.outputHTTPConfig.OriginalHost = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, options := range Settings.outputHTTP {
|
||||
registerPlugin(NewHTTPOutput, options, &Settings.outputHTTPConfig)
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ type Listener struct {
|
||||
|
||||
// Expect: 100-continue request is send in 2 tcp messages
|
||||
// We store ACK aliases to merge this packets together
|
||||
ackAliases map[uint32]uint32
|
||||
ackAliases map[uint32]uint32
|
||||
// To get ACK of second message we need to compute its Seq and wait for them message
|
||||
seqWithData map[uint32]uint32
|
||||
|
||||
// Messages ready to be send to client
|
||||
packetsChan chan *TCPPacket
|
||||
packetsChan chan *TCPPacket
|
||||
|
||||
// Messages ready to be send to client
|
||||
messagesChan chan *TCPMessage
|
||||
|
||||
Reference in New Issue
Block a user