{"action":"created","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4253","repository_url":"https://api.github.com/repos/tomchristie/django-rest-framework","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4253/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4253/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4253/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/4253","id":164746143,"number":4253,"title":"Response Content-Type potentially malformed","user":{"login":"lsowen","id":1014577,"avatar_url":"https://avatars.githubusercontent.com/u/1014577?v=3","gravatar_id":"","url":"https://api.github.com/users/lsowen","html_url":"https://github.com/lsowen","followers_url":"https://api.github.com/users/lsowen/followers","following_url":"https://api.github.com/users/lsowen/following{/other_user}","gists_url":"https://api.github.com/users/lsowen/gists{/gist_id}","starred_url":"https://api.github.com/users/lsowen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsowen/subscriptions","organizations_url":"https://api.github.com/users/lsowen/orgs","repos_url":"https://api.github.com/users/lsowen/repos","events_url":"https://api.github.com/users/lsowen/events{/privacy}","received_events_url":"https://api.github.com/users/lsowen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/labels/Bug","name":"Bug","color":"e10c02"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/milestones/35","html_url":"https://github.com/tomchristie/django-rest-framework/milestones/3.4.0%20Release","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/milestones/35/labels","id":1381458,"number":35,"title":"3.4.0 Release","description":"","creator":{"login":"tomchristie","id":647359,"avatar_url":"https://avatars.githubusercontent.com/u/647359?v=3","gravatar_id":"","url":"https://api.github.com/users/tomchristie","html_url":"https://github.com/tomchristie","followers_url":"https://api.github.com/users/tomchristie/followers","following_url":"https://api.github.com/users/tomchristie/following{/other_user}","gists_url":"https://api.github.com/users/tomchristie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomchristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomchristie/subscriptions","organizations_url":"https://api.github.com/users/tomchristie/orgs","repos_url":"https://api.github.com/users/tomchristie/repos","events_url":"https://api.github.com/users/tomchristie/events{/privacy}","received_events_url":"https://api.github.com/users/tomchristie/received_events","type":"User","site_admin":false},"open_issues":22,"closed_issues":81,"state":"open","created_at":"2015-10-28T13:51:54Z","updated_at":"2016-07-11T11:04:45Z","due_on":"2016-07-28T23:00:00Z","closed_at":null},"comments":6,"created_at":"2016-07-11T01:45:05Z","updated_at":"2016-07-11T12:42:06Z","closed_at":"2016-07-11T11:04:12Z","body":"## Checklist\r\n\r\n- [x] I have verified that that issue exists against the `master` branch of Django REST framework.\r\n- [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.\r\n- [x] This is not a usage question. (Those should be directed to the [discussion group](https://groups.google.com/forum/#!forum/django-rest-framework) instead.)\r\n- [ ] This cannot be dealt with as a third party library. (We prefer new functionality to be [in the form of third party libraries](http://www.django-rest-framework.org/topics/third-party-resources/#about-third-party-packages) where possible.)\r\n- [x] I have reduced the issue to the simplest possible case.\r\n- [ ] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)\r\n\r\n## Problem description\r\n\r\nThe default request header 'Accept' on many browsers is something like `Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`.  This means that currently, if the response is not `text/html`, then the response `Content-Type` incorrectly contains the `q=` parameter.  (According to [this](http://stackoverflow.com/a/10496722/3108853), the `q` parameter specifies which content-types the browser prefers).\r\n\r\nIt looks like it is occurring because:\r\n\r\n1. [DefaultContentNegotiation.select_renderer](https://github.com/tomchristie/django-rest-framework/blob/10a080d395b8f1fc5cef0778cd2a40c3d81dfe19/rest_framework/negotiation.py#L67-L72) returns the `full_media_type` (which includes the extra `Accept` \"parameters\" like `q`)\r\n2. [ApiView.perform_content_negotiation](https://github.com/tomchristie/django-rest-framework/blob/10a080d395b8f1fc5cef0778cd2a40c3d81dfe19/rest_framework/views.py#L296) returns the `renderer, full_media_type` tuple\r\n3. [ApiView.initial](https://github.com/tomchristie/django-rest-framework/blob/10a080d395b8f1fc5cef0778cd2a40c3d81dfe19/rest_framework/views.py#L376-L377) sets `request.accepted_media_type` equal to that `full_media_type`\r\n4. [ApiView.finalize_response](https://github.com/tomchristie/django-rest-framework/blob/10a080d395b8f1fc5cef0778cd2a40c3d81dfe19/rest_framework/views.py#L405) sets `response.accepted_media_type` equal to `request.accepted_media_type`\r\n3. [Response.rendered_content](https://github.com/tomchristie/django-rest-framework/blob/bb56ca46ed6c07db0146dbdc61c672ff25f127de/rest_framework/response.py#L65-L69) is setting the response `Content-Type` to the value of `response.accepted_media_type`.\r\n\r\nThis only came to light because I'm running nginx in front of django, and it was not recognizing the content-type (as `application/json` is different from `application/json;q=0.9`).  As far as I can tell, this is actually an invalid Content-Type (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17).\r\n\r\n## Steps to reproduce\r\n\r\ncurl --verbose http://example.com/api/model?format=json  --H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' > /dev/null\r\n\r\n## Expected behavior\r\n\r\n`Content-Type: application/json; charset=utf-8`\r\n\r\n## Actual behavior\r\n\r\n`Content-Type: application/json;q=0.9; charset=utf-8`"},"comment":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/comments/231723143","html_url":"https://github.com/tomchristie/django-rest-framework/issues/4253#issuecomment-231723143","issue_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4253","id":231723143,"user":{"login":"tomchristie","id":647359,"avatar_url":"https://avatars.githubusercontent.com/u/647359?v=3","gravatar_id":"","url":"https://api.github.com/users/tomchristie","html_url":"https://github.com/tomchristie","followers_url":"https://api.github.com/users/tomchristie/followers","following_url":"https://api.github.com/users/tomchristie/following{/other_user}","gists_url":"https://api.github.com/users/tomchristie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomchristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomchristie/subscriptions","organizations_url":"https://api.github.com/users/tomchristie/orgs","repos_url":"https://api.github.com/users/tomchristie/repos","events_url":"https://api.github.com/users/tomchristie/events{/privacy}","received_events_url":"https://api.github.com/users/tomchristie/received_events","type":"User","site_admin":false},"created_at":"2016-07-11T12:42:06Z","updated_at":"2016-07-11T12:42:06Z","body":"Most welcome"}}
{"actor":{"display_login":"tomchristie"}}