Merge pull request #108 from matzhouse/master

gor issue 74
This commit is contained in:
Leonid Bugaev
2014-08-12 12:44:59 +04:00
2 changed files with 36 additions and 1 deletions
+15 -1
View File
@@ -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
View File
@@ -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)