{"action":"created","issue":{"url":"https://api.github.com/repos/playframework/playframework/issues/4681","labels_url":"https://api.github.com/repos/playframework/playframework/issues/4681/labels{/name}","comments_url":"https://api.github.com/repos/playframework/playframework/issues/4681/comments","events_url":"https://api.github.com/repos/playframework/playframework/issues/4681/events","html_url":"https://github.com/playframework/playframework/issues/4681","id":88770357,"number":4681,"title":"Repeated content type headers in WS on POST","user":{"login":"wsargent","id":71236,"avatar_url":"https://avatars.githubusercontent.com/u/71236?v=3","gravatar_id":"","url":"https://api.github.com/users/wsargent","html_url":"https://github.com/wsargent","followers_url":"https://api.github.com/users/wsargent/followers","following_url":"https://api.github.com/users/wsargent/following{/other_user}","gists_url":"https://api.github.com/users/wsargent/gists{/gist_id}","starred_url":"https://api.github.com/users/wsargent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wsargent/subscriptions","organizations_url":"https://api.github.com/users/wsargent/orgs","repos_url":"https://api.github.com/users/wsargent/repos","events_url":"https://api.github.com/users/wsargent/events{/privacy}","received_events_url":"https://api.github.com/users/wsargent/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/playframework/playframework/labels/defect","name":"defect","color":"e10c02"}],"state":"open","locked":false,"assignee":{"login":"wsargent","id":71236,"avatar_url":"https://avatars.githubusercontent.com/u/71236?v=3","gravatar_id":"","url":"https://api.github.com/users/wsargent","html_url":"https://github.com/wsargent","followers_url":"https://api.github.com/users/wsargent/followers","following_url":"https://api.github.com/users/wsargent/following{/other_user}","gists_url":"https://api.github.com/users/wsargent/gists{/gist_id}","starred_url":"https://api.github.com/users/wsargent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wsargent/subscriptions","organizations_url":"https://api.github.com/users/wsargent/orgs","repos_url":"https://api.github.com/users/wsargent/repos","events_url":"https://api.github.com/users/wsargent/events{/privacy}","received_events_url":"https://api.github.com/users/wsargent/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-06-16T16:11:10Z","updated_at":"2016-01-19T11:51:55Z","closed_at":null,"body":"From https://groups.google.com/d/topic/play-framework/mF-Rqh_ljEA/discussion\r\n\r\nwenn I do that:\r\n\r\n```scala\r\nWS.url(url)\r\n     .withHeaders(\"x-api-version\" -> \"1.0\")\r\n     .withRequestTimeout(2000)\r\n     .post(authData)\r\n     .map { response =>\r\n     response.status match {\r\n       case s if s < 300 =>\r\n         Ok(response.json)\r\n       case _ =>\r\n         Ok(\"Status: \" + response.status + \"/ Error: \" + response.body)\r\n     }\r\n   }\r\n```\r\n\r\nI see this request:\r\n\r\n```\r\nRequest DefaultHttpRequest(chunked: false)\r\nPOST /api/login/ HTTP/1.1\r\nHost: 62.67.13.54\r\nContent-Type: application/json; charset=utf-8\r\nConnection: keep-alive\r\nAccept: */*\r\nUser-Agent: HbbTVPlugin\r\nContent-Length: 37\r\n```\r\n\r\nThe the target system has a problem processing `\"charset=utf-8\"`, so I tried his:\r\n\r\n```scala\r\nWS.url(url)\r\n     .withHeaders(\"x-api-version\" -> \"1.0\")\r\n     .withHeaders(CONTENT_TYPE -> \"application/json\")\r\n     .withRequestTimeout(2000)\r\n     .post(authData)\r\n     .map { response =>\r\n     response.status match {\r\n       case s if s < 300 =>\r\n         Ok(response.json)\r\n       case _ =>\r\n         Ok(\"Status: \" + response.status + \"/ Error: \" + response.body)\r\n     }\r\n   }\r\n```\r\n\r\nand I get this request:\r\n\r\n```\r\nRequest DefaultHttpRequest(chunked: false)\r\nPOST /api/login/ HTTP/1.1\r\nHost: 62.67.13.54\r\nContent-Type: application/json\r\nContent-Type: application/json; charset=utf-8\r\nConnection: keep-alive\r\nAccept: */*\r\nUser-Agent: HbbTVPlugin\r\nContent-Length: 37\r\n```\r\n\r\nI did not expect to get the same header key (`Content-Type`) twice?\r\n\r\nWhat can I do to change the content type, without getting two content-type header?"},"comment":{"url":"https://api.github.com/repos/playframework/playframework/issues/comments/172827636","html_url":"https://github.com/playframework/playframework/issues/4681#issuecomment-172827636","issue_url":"https://api.github.com/repos/playframework/playframework/issues/4681","id":172827636,"user":{"login":"mkurz","id":644927,"avatar_url":"https://avatars.githubusercontent.com/u/644927?v=3","gravatar_id":"","url":"https://api.github.com/users/mkurz","html_url":"https://github.com/mkurz","followers_url":"https://api.github.com/users/mkurz/followers","following_url":"https://api.github.com/users/mkurz/following{/other_user}","gists_url":"https://api.github.com/users/mkurz/gists{/gist_id}","starred_url":"https://api.github.com/users/mkurz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkurz/subscriptions","organizations_url":"https://api.github.com/users/mkurz/orgs","repos_url":"https://api.github.com/users/mkurz/repos","events_url":"https://api.github.com/users/mkurz/events{/privacy}","received_events_url":"https://api.github.com/users/mkurz/received_events","type":"User","site_admin":false},"created_at":"2016-01-19T11:51:55Z","updated_at":"2016-01-19T11:51:55Z","body":"Update for Play 2.4.6:\r\n\r\nUsing **Java**:\r\n```java\r\n\tWS.url(url)\r\n\t\t.setHeader(\"x-api-version\", \"1.0\")\r\n\t\t.setHeader(CONTENT_TYPE, \"application/json\")\r\n\t\t.setHeader(CONTENT_TYPE, \"application/xml\")\r\n\t\t...\r\n```\r\nproduces\r\n```\r\nPOST / HTTP/1.1\r\nx-api-version: 1.0\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 4\r\nConnection: keep-alive\r\nHost: google.com\r\nAccept: */*\r\nUser-Agent: AHC/1.0\r\n```\r\n\r\nUsing **Scala**:\r\n```scala\r\n\tWS.url(\"http://google.com\")\r\n\t\t.withHeaders(\"x-api-version\" -> \"1.0\")\r\n\t\t.withHeaders(CONTENT_TYPE -> \"application/json\")\r\n\t\t.withHeaders(CONTENT_TYPE -> \"application/xml\")\r\n\t\t...\r\n```\r\nproduces\r\n```\r\nPOST / HTTP/1.1\r\nx-api-version: 1.0\r\nContent-Type: application/json\r\nContent-Type: application/xml\r\nContent-Length: 4\r\nConnection: keep-alive\r\nHost: google.com\r\nAccept: */*\r\nUser-Agent: AHC/1.0\r\n```\r\n\r\n\r\nSo the Java and Scala versions differ. In Java the first header is used where probably the second one should be used instead (because it should override the first one). The Scala version still produces duplicate headers.\r\n\r\n@wsargent @marcospereira Is the Java WS not using the Scala WS code within Play?\r\n\r\nI also tried async-http-client 2.0.0-RC7 and it still fails here as well:\r\n```java\r\nfinal AsyncHttpClient client = new DefaultAsyncHttpClient();\r\nclient.prepareGet(\"http://google.com\").addHeader(\"Content-Type\", \"utf-8\").addHeader(\"Content-Type\", \"application/json\").execute();\r\n```\r\nproduces\r\n```\r\nGET / HTTP/1.1\r\nContent-Type: utf-8\r\nContent-Type: application/json\r\nHost: google.com\r\nAccept: */*\r\nUser-Agent: AHC/2.0\r\n```"}}