mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
+15
-1
@@ -131,7 +131,7 @@ func (o *HTTPOutput) sendRequest(client *http.Client, data []byte) {
|
||||
request.URL, _ = url.ParseRequestURI(URL)
|
||||
|
||||
for _, header := range o.headers {
|
||||
request.Header.Set(header.Name, header.Value)
|
||||
SetHeader(request, header.Name, header.Value)
|
||||
}
|
||||
|
||||
resp, err := client.Do(request)
|
||||
@@ -151,6 +151,20 @@ func (o *HTTPOutput) sendRequest(client *http.Client, data []byte) {
|
||||
|
||||
}
|
||||
|
||||
func SetHeader(request *http.Request, name string, value string) {
|
||||
|
||||
// Need to check here for the Host header as it needs to be set on the request and not as a separate header
|
||||
// http.ReadRequest sets it by default to the URL Host of the request being read
|
||||
if name == "Host" {
|
||||
request.Host = value
|
||||
} else {
|
||||
request.Header.Set(name, value)
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (o *HTTPOutput) String() string {
|
||||
return "HTTP output: " + o.address
|
||||
}
|
||||
|
||||
@@ -21,6 +21,27 @@ func startHTTP(cb func(*http.Request)) net.Listener {
|
||||
return listener
|
||||
}
|
||||
|
||||
func TestSetHeader(t *testing.T) {
|
||||
|
||||
req := &http.Request{
|
||||
Header: make(map[string][]string),
|
||||
}
|
||||
req.Host = "test.com"
|
||||
|
||||
SetHeader(req, "Host", "test2.com")
|
||||
|
||||
if req.Host != "test2.com" {
|
||||
t.Error("Expected test2.com - got ", req.Host)
|
||||
}
|
||||
|
||||
SetHeader(req, "test_header", "test_value")
|
||||
|
||||
if req.Header.Get("test_header") != "test_value" {
|
||||
t.Error("Wrong header value found")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestHTTPOutput(t *testing.T) {
|
||||
wg := new(sync.WaitGroup)
|
||||
quit := make(chan int)
|
||||
|
||||
Reference in New Issue
Block a user