mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 08:46:48 +00:00
Adds HTTP Host entry
Fixes: https://github.com/openfaas-incubator/of-watchdog/pull/24 Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
parent
44ceb8da22
commit
a4c867fd8f
@ -249,6 +249,10 @@ func getAdditionalEnvs(config *WatchdogConfig, r *http.Request, method string) [
|
||||
envs = append(envs, fmt.Sprintf("Http_Path=%s", r.URL.Path))
|
||||
}
|
||||
|
||||
if len(r.Host) > 0 {
|
||||
envs = append(envs, fmt.Sprintf("Http_Host=%s", r.Host))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return envs
|
||||
|
@ -104,6 +104,66 @@ func TestHandler_HasCustomHeaderInFunction_WithCgiMode_AndBody(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler_HasHostHeaderWhenSet(t *testing.T) {
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
body := "test"
|
||||
req, err := http.NewRequest(http.MethodPost, "http://gateway/function", bytes.NewBufferString(body))
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
config := WatchdogConfig{
|
||||
faasProcess: "env",
|
||||
cgiHeaders: true,
|
||||
}
|
||||
handler := makeRequestHandler(&config)
|
||||
handler(rr, req)
|
||||
|
||||
required := http.StatusOK
|
||||
if status := rr.Code; status != required {
|
||||
t.Errorf("handler returned wrong status code - got: %v, want: %v",
|
||||
status, required)
|
||||
}
|
||||
|
||||
read, _ := ioutil.ReadAll(rr.Body)
|
||||
val := string(read)
|
||||
if !strings.Contains(val, fmt.Sprintf("Http_Host=%s", req.URL.Host)) {
|
||||
t.Errorf("'env' should have printed: Http_Host=0, got: %s\n", val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler_HostHeader_Empty_WhenNotSet(t *testing.T) {
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
body := "test"
|
||||
req, err := http.NewRequest(http.MethodPost, "/function", bytes.NewBufferString(body))
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
config := WatchdogConfig{
|
||||
faasProcess: "env",
|
||||
cgiHeaders: true,
|
||||
}
|
||||
handler := makeRequestHandler(&config)
|
||||
handler(rr, req)
|
||||
|
||||
required := http.StatusOK
|
||||
if status := rr.Code; status != required {
|
||||
t.Errorf("handler returned wrong status code - got: %v, want: %v",
|
||||
status, required)
|
||||
}
|
||||
|
||||
read, _ := ioutil.ReadAll(rr.Body)
|
||||
val := string(read)
|
||||
if strings.Contains(val, fmt.Sprintf("Http_Host=%s", req.URL.Host)) {
|
||||
t.Errorf("Http_Host should not have been given, but was: %s\n", val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler_StderrWritesToStderr_CombinedOutput_False(t *testing.T) {
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user