{"action":"created","issue":{"url":"https://api.github.com/repos/openfaas/faas/issues/312","repository_url":"https://api.github.com/repos/openfaas/faas","labels_url":"https://api.github.com/repos/openfaas/faas/issues/312/labels{/name}","comments_url":"https://api.github.com/repos/openfaas/faas/issues/312/comments","events_url":"https://api.github.com/repos/openfaas/faas/issues/312/events","html_url":"https://github.com/openfaas/faas/issues/312","id":266427820,"number":312,"title":"Function return Content-Type not honored by Gateway","user":{"login":"mcgoober","id":1300558,"avatar_url":"https://avatars1.githubusercontent.com/u/1300558?v=4","gravatar_id":"","url":"https://api.github.com/users/mcgoober","html_url":"https://github.com/mcgoober","followers_url":"https://api.github.com/users/mcgoober/followers","following_url":"https://api.github.com/users/mcgoober/following{/other_user}","gists_url":"https://api.github.com/users/mcgoober/gists{/gist_id}","starred_url":"https://api.github.com/users/mcgoober/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcgoober/subscriptions","organizations_url":"https://api.github.com/users/mcgoober/orgs","repos_url":"https://api.github.com/users/mcgoober/repos","events_url":"https://api.github.com/users/mcgoober/events{/privacy}","received_events_url":"https://api.github.com/users/mcgoober/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"ericstoekl","id":1483261,"avatar_url":"https://avatars2.githubusercontent.com/u/1483261?v=4","gravatar_id":"","url":"https://api.github.com/users/ericstoekl","html_url":"https://github.com/ericstoekl","followers_url":"https://api.github.com/users/ericstoekl/followers","following_url":"https://api.github.com/users/ericstoekl/following{/other_user}","gists_url":"https://api.github.com/users/ericstoekl/gists{/gist_id}","starred_url":"https://api.github.com/users/ericstoekl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericstoekl/subscriptions","organizations_url":"https://api.github.com/users/ericstoekl/orgs","repos_url":"https://api.github.com/users/ericstoekl/repos","events_url":"https://api.github.com/users/ericstoekl/events{/privacy}","received_events_url":"https://api.github.com/users/ericstoekl/received_events","type":"User","site_admin":false},"assignees":[{"login":"ericstoekl","id":1483261,"avatar_url":"https://avatars2.githubusercontent.com/u/1483261?v=4","gravatar_id":"","url":"https://api.github.com/users/ericstoekl","html_url":"https://github.com/ericstoekl","followers_url":"https://api.github.com/users/ericstoekl/followers","following_url":"https://api.github.com/users/ericstoekl/following{/other_user}","gists_url":"https://api.github.com/users/ericstoekl/gists{/gist_id}","starred_url":"https://api.github.com/users/ericstoekl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericstoekl/subscriptions","organizations_url":"https://api.github.com/users/ericstoekl/orgs","repos_url":"https://api.github.com/users/ericstoekl/repos","events_url":"https://api.github.com/users/ericstoekl/events{/privacy}","received_events_url":"https://api.github.com/users/ericstoekl/received_events","type":"User","site_admin":false},{"login":"alexellis","id":6358735,"avatar_url":"https://avatars1.githubusercontent.com/u/6358735?v=4","gravatar_id":"","url":"https://api.github.com/users/alexellis","html_url":"https://github.com/alexellis","followers_url":"https://api.github.com/users/alexellis/followers","following_url":"https://api.github.com/users/alexellis/following{/other_user}","gists_url":"https://api.github.com/users/alexellis/gists{/gist_id}","starred_url":"https://api.github.com/users/alexellis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexellis/subscriptions","organizations_url":"https://api.github.com/users/alexellis/orgs","repos_url":"https://api.github.com/users/alexellis/repos","events_url":"https://api.github.com/users/alexellis/events{/privacy}","received_events_url":"https://api.github.com/users/alexellis/received_events","type":"User","site_admin":false}],"milestone":null,"comments":7,"created_at":"2017-10-18T09:44:25Z","updated_at":"2017-12-11T13:55:27Z","closed_at":"2017-10-20T20:47:32Z","author_association":"NONE","body":"## Expected Behaviour\r\nThe watchdog has a setting 'content_type' which when set forces the return content-type of a function. This content-type that is returned by the watchdog should be also be returned by the gateway.\r\n\r\n## Current Behaviour\r\nThe gateway returns the same content-type as the request. i.e if you POST with content-type 'application/json' in the request, then 'application/json' is in the response, no matter what the function actually returns.\r\n\r\n## Possible Solution\r\nhttps://github.com/openfaas/faas/blob/master/gateway/handlers/proxy.go#L173\r\nAt the time of writing...\r\nhttps://github.com/openfaas/faas/blob/dde98eb582c381d07d4b7c6842b815c455179b57/gateway/handlers/proxy.go#L173\r\n\r\nThis line of code forces response content-type to the request and overwrites the function return content-type. The comment above the line suggests that this may been thought about.\r\n\r\nRemoval of this line prevents the content-type from being overwritten and allows the gateway to return the correct content-type for the function.\r\n\r\n## Steps to Reproduce (for bugs)\r\n1. Create a function with env var 'content_type' set to 'text/html'\r\n2. POST to the function with request content-type say.. 'application/json'\r\n3. Function will return 'application/json', this is true for any content-type\r\n\r\n## Context\r\nFound this issue whilst attempting to make a function that returned HTML for a browser and thus develop a web application as a function or set of functions. The browser won't display the returned HTML  unless the content-type is 'text/html'.  \r\nThis solution also requires the ability to call a function with a GET, but I've accomplished this in another way.\r\n\r\n## Your Environment\r\n* Gateway 0.6.6d\r\n* Watchdog 0.6.6d\r\n* Docker Swarm 17.06.1-ce\r\n"},"comment":{"url":"https://api.github.com/repos/openfaas/faas/issues/comments/350730609","html_url":"https://github.com/openfaas/faas/issues/312#issuecomment-350730609","issue_url":"https://api.github.com/repos/openfaas/faas/issues/312","id":350730609,"user":{"login":"mcgoober","id":1300558,"avatar_url":"https://avatars1.githubusercontent.com/u/1300558?v=4","gravatar_id":"","url":"https://api.github.com/users/mcgoober","html_url":"https://github.com/mcgoober","followers_url":"https://api.github.com/users/mcgoober/followers","following_url":"https://api.github.com/users/mcgoober/following{/other_user}","gists_url":"https://api.github.com/users/mcgoober/gists{/gist_id}","starred_url":"https://api.github.com/users/mcgoober/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcgoober/subscriptions","organizations_url":"https://api.github.com/users/mcgoober/orgs","repos_url":"https://api.github.com/users/mcgoober/repos","events_url":"https://api.github.com/users/mcgoober/events{/privacy}","received_events_url":"https://api.github.com/users/mcgoober/received_events","type":"User","site_admin":false},"created_at":"2017-12-11T13:55:27Z","updated_at":"2017-12-11T13:55:27Z","author_association":"NONE","body":"I understand your need for a repro, and if I have to go to the trouble I will, but please check your code first.\r\n\r\nYour tests for the new code in tests/proxy_tests.go are great, and work, because they call GetContentType with the correct parameter order (Request, Response, DefaultHeader). Your code in gateway proxy.go does not. \r\n\r\nThe fix for this is to change the call to GetContentType in proxy.go to from...\r\n`w.Header().Set(\"Content-Type\", GetContentType(response.Header, r.Header, defaultHeader))`\r\nto this...\r\n`w.Header().Set(\"Content-Type\", GetContentType(r.Header, response.Header, defaultHeader))`\r\n"}}
{"actor":{"display_login":"mcgoober"}}