From 4d785c8dfba82acc3a992988ffba7a546de28fb8 Mon Sep 17 00:00:00 2001 From: Eric Stoekl Date: Tue, 12 Dec 2017 08:07:12 -0800 Subject: [PATCH] Remove Content-Type forwarding from Request Signed-off-by: Eric Stoekl --- gateway/handlers/proxy.go | 21 ------------------ gateway/tests/proxy_test.go | 44 ------------------------------------- 2 files changed, 65 deletions(-) delete mode 100644 gateway/tests/proxy_test.go diff --git a/gateway/handlers/proxy.go b/gateway/handlers/proxy.go index 57d806d9..012c1290 100644 --- a/gateway/handlers/proxy.go +++ b/gateway/handlers/proxy.go @@ -160,10 +160,6 @@ func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.Metri clientHeader := w.Header() copyHeaders(&clientHeader, &response.Header) - defaultHeader := "text/plain" - - w.Header().Set("Content-Type", GetContentType(response.Header, r.Header, defaultHeader)) - writeHead(service, metrics, response.StatusCode, w) if response.Body != nil { @@ -171,23 +167,6 @@ func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.Metri } } -// GetContentType resolves the correct Content-Tyoe for a proxied function -func GetContentType(request http.Header, proxyResponse http.Header, defaultValue string) string { - responseHeader := proxyResponse.Get("Content-Type") - requestHeader := request.Get("Content-Type") - - var headerContentType string - if len(responseHeader) > 0 { - headerContentType = responseHeader - } else if len(requestHeader) > 0 { - headerContentType = requestHeader - } else { - headerContentType = defaultValue - } - - return headerContentType -} - func copyHeaders(destination *http.Header, source *http.Header) { for k, v := range *source { vClone := make([]string, len(v)) diff --git a/gateway/tests/proxy_test.go b/gateway/tests/proxy_test.go deleted file mode 100644 index 6f8992e6..00000000 --- a/gateway/tests/proxy_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package tests - -import ( - "net/http" - "testing" - - "github.com/openfaas/faas/gateway/handlers" -) - -func Test_GetContentType_UsesResponseValue(t *testing.T) { - request := http.Header{} - request.Add("Content-Type", "text/plain") - response := http.Header{} - response.Add("Content-Type", "text/html") - - contentType := handlers.GetContentType(request, response, "default") - if contentType != response.Get("Content-Type") { - t.Errorf("Got: %s, want: %s", contentType, response.Get("Content-Type")) - } -} - -func Test_GetContentType_UsesRequest_WhenResponseEmpty(t *testing.T) { - request := http.Header{} - request.Add("Content-Type", "text/plain") - response := http.Header{} - response.Add("Content-Type", "") - - contentType := handlers.GetContentType(request, response, "default") - if contentType != request.Get("Content-Type") { - t.Errorf("Got: %s, want: %s", contentType, request.Get("Content-Type")) - } -} - -func Test_GetContentType_UsesDefaultWhenRequestResponseEmpty(t *testing.T) { - request := http.Header{} - request.Add("Content-Type", "") - response := http.Header{} - response.Add("Content-Type", "") - - contentType := handlers.GetContentType(request, response, "default") - if contentType != "default" { - t.Errorf("Got: %s, want: %s", contentType, "default") - } -}