{"action":"created","issue":{"url":"https://api.github.com/repos/benoitc/gunicorn/issues/1041","labels_url":"https://api.github.com/repos/benoitc/gunicorn/issues/1041/labels{/name}","comments_url":"https://api.github.com/repos/benoitc/gunicorn/issues/1041/comments","events_url":"https://api.github.com/repos/benoitc/gunicorn/issues/1041/events","html_url":"https://github.com/benoitc/gunicorn/pull/1041","id":82272794,"number":1041,"title":"empty ACCEPT header support","user":{"login":"mkorenkov","id":643349,"avatar_url":"https://avatars.githubusercontent.com/u/643349?v=3","gravatar_id":"","url":"https://api.github.com/users/mkorenkov","html_url":"https://github.com/mkorenkov","followers_url":"https://api.github.com/users/mkorenkov/followers","following_url":"https://api.github.com/users/mkorenkov/following{/other_user}","gists_url":"https://api.github.com/users/mkorenkov/gists{/gist_id}","starred_url":"https://api.github.com/users/mkorenkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkorenkov/subscriptions","organizations_url":"https://api.github.com/users/mkorenkov/orgs","repos_url":"https://api.github.com/users/mkorenkov/repos","events_url":"https://api.github.com/users/mkorenkov/events{/privacy}","received_events_url":"https://api.github.com/users/mkorenkov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/benoitc/gunicorn/labels/Feedback%20Requested","name":"Feedback Requested","color":"ffb114"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-29T05:33:12Z","updated_at":"2015-05-29T20:27:24Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/benoitc/gunicorn/pulls/1041","html_url":"https://github.com/benoitc/gunicorn/pull/1041","diff_url":"https://github.com/benoitc/gunicorn/pull/1041.diff","patch_url":"https://github.com/benoitc/gunicorn/pull/1041.patch"},"body":"Some of our legacy clients stopped working ffter we upgraded from _18.0_ to _19.3_.\r\nAs we find out, the reason was they were sending an empty `Accept` header. \r\nSome authors recommend replacing treating empty `Accept:` as `Accept: */*`([link](http://stackoverflow.com/questions/12130910/how-to-interpret-empty-http-accept-header)).\r\nThis fix is treating `Accept:` as `Accept: */*`.\r\n\r\n**Before**:\r\n\r\n    curl -i 'https://host.example.com/' -H 'Accept:'\r\n\r\n>HTTP/1.1 500 Internal Server Error UNKNOWN STATUS CODE\r\n>Server: nginx/1.8.0\r\n>Date: Thu, 28 May 2015 14:56:20 GMT\r\n>Content-Type: text/html; charset=utf-8\r\n>Transfer-Encoding: chunked\r\n>Connection: keep-alive\r\n\r\nlog:\r\n>2015-05-28 07:56:20 +0000] [19480] [ERROR] Error handling request\r\n>Traceback (most recent call last):\r\n>  File \".../env/local/lib/python2.7/site-packages/gunicorn/workers/sync.py\", line 177, in handle_request\r\n>    resp.write(item)\r\n>  File \".../env/local/lib/python2.7/site-packages/gunicorn/http/wsgi.py\", line 326, in write\r\n>    raise TypeError('%r is not a byte' % arg)\r\n>TypeError: u'The server has either erred or is incapable of performing\\r\\nthe requested operation.\\r\\n<br><br>\\nNone\\nNone' is not a byte\r\n\r\n**After**:\r\n\r\n    curl -i 'http://127.0.0.1:8000' -H 'Accept:' \r\n\r\n>HTTP/1.1 302 FOUND\r\n>Server: gunicorn/19.3.0\r\n>Date: Fri, 29 May 2015 04:22:28 GMT\r\n>Connection: close\r\n>Transfer-Encoding: chunked\r\n>Vary: Cookie\r\n>Content-Type: text/html; charset=utf-8\r\n>Location: http://127.0.0.1:8000/user/login/?next=/\r\n\r\n    curl -i 'http://127.0.0.1:8000' -H 'Accept: */*' \r\n\r\n>HTTP/1.1 302 FOUND\r\n>Server: gunicorn/19.3.0\r\n>Date: Fri, 29 May 2015 04:22:32 GMT\r\n>Connection: close\r\n>Transfer-Encoding: chunked\r\n>Vary: Cookie\r\n>Content-Type: text/html; charset=utf-8\r\n>Location: http://127.0.0.1:8000/user/login/?next=/"},"comment":{"url":"https://api.github.com/repos/benoitc/gunicorn/issues/comments/106926606","html_url":"https://github.com/benoitc/gunicorn/pull/1041#issuecomment-106926606","issue_url":"https://api.github.com/repos/benoitc/gunicorn/issues/1041","id":106926606,"user":{"login":"benoitc","id":14498,"avatar_url":"https://avatars.githubusercontent.com/u/14498?v=3","gravatar_id":"","url":"https://api.github.com/users/benoitc","html_url":"https://github.com/benoitc","followers_url":"https://api.github.com/users/benoitc/followers","following_url":"https://api.github.com/users/benoitc/following{/other_user}","gists_url":"https://api.github.com/users/benoitc/gists{/gist_id}","starred_url":"https://api.github.com/users/benoitc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benoitc/subscriptions","organizations_url":"https://api.github.com/users/benoitc/orgs","repos_url":"https://api.github.com/users/benoitc/repos","events_url":"https://api.github.com/users/benoitc/events{/privacy}","received_events_url":"https://api.github.com/users/benoitc/received_events","type":"User","site_admin":false},"created_at":"2015-05-29T20:27:24Z","updated_at":"2015-05-29T20:27:24Z","body":"Hrm without any patch on the latest master with python 3.4x or python 2.7x  gunicorn is able to accept an empty header:\r\n\r\n![screen shot 2015-05-29 at 23 18 20](https://cloud.githubusercontent.com/assets/14498/7891912/143d9fe6-0659-11e5-920f-357be72bdafe.png)\r\n\r\nThe 500 error is most likely due to this error:\r\n\r\n    File \".../env/local/lib/python2.7/site-packages/gunicorn/http/wsgi.py\", line 326, in write\r\n    raise TypeError('%r is not a byte' % arg)\r\n    TypeError: u'The server has either erred or is incapable of performing\\r\\nthe requested operation.\\r\\n\r\n\r\nWhich means that you're probably returning an unicode to the response. Could you check that?\r\n\r\nLooking at the [spec](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1) we can read the following:\r\n\r\n> If no Accept header field is present, then it is assumed that the client accepts all media types.\r\n\r\nFor me it seems that Gunicorn is doing the appropriate job there. As a gateway it shouldn't change the request headers also in my opinion."}}