diff --git a/gateway/handlers/proxy.go b/gateway/handlers/proxy.go
index 78c1069b833bf1591bedafaf7cddbc7f243d4b74..ee968c75459d86395a258f6cfbf34ea6c258f069 100644
--- a/gateway/handlers/proxy.go
+++ b/gateway/handlers/proxy.go
@@ -168,23 +168,29 @@ func invokeService(w http.ResponseWriter, r *http.Request, metrics metrics.Metri
 	clientHeader := w.Header()
 	copyHeaders(&clientHeader, &response.Header)
 
-	responseHeader := response.Header.Get("Content-Type")
-	requestHeader := r.Header.Get("Content-Type")
 	defaultHeader := "text/plain"
-	contentTypeField := "Content-Type"
 
-	fmt.Printf("Req %s Res %s\n", requestHeader, responseHeader)
+	w.Header().Set("Content-Type", GetContentType(response.Header, r.Header, defaultHeader))
 
+	writeHead(service, metrics, response.StatusCode, w)
+	w.Write(responseBody)
+}
+
+// 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 {
-		w.Header().Set(contentTypeField, responseHeader)
+		headerContentType = responseHeader
 	} else if len(requestHeader) > 0 {
-		w.Header().Set(contentTypeField, requestHeader)
+		headerContentType = requestHeader
 	} else {
-		w.Header().Set(contentTypeField, defaultHeader)
+		headerContentType = defaultValue
 	}
 
-	writeHead(service, metrics, response.StatusCode, w)
-	w.Write(responseBody)
+	return headerContentType
 }
 
 func copyHeaders(destination *http.Header, source *http.Header) {
diff --git a/gateway/tests/proxy_test.go b/gateway/tests/proxy_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..deba790b54c12bcdf775ba03e9788ba379857c50
--- /dev/null
+++ b/gateway/tests/proxy_test.go
@@ -0,0 +1,46 @@
+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")
+	}
+
+}