playframework/playframework — pull request #3119 by gmethvin (2014-07-01 20:38:38+00:00)
Title: FakeRequest Content-Type Header Overwritten

I have a controller that expects xml content in utf-16le. I have written a custom body parser to handle this as I could not find an easier way. At any rate, trying to test this controller I need to send utf-16le encoded xml, with a Content-Type of "text/xml". I have tried to create the FakeRequest multiple ways, setting the correct "Content-Type" header, but when the request is actually executed the Content-Type is set to "application/octet-stream" thus does not validate against my body parser.

```
val bytes = xml.toString.getBytes("utf-16le")
val req = FakeRequest(PUT, "/process")
.withRawBody(bytes)
.withHeaders(
("Accept", "text/xml"),
("Accept-Charset", "utf-16"),
("Content-Type", "text/xml"))
val res = route(req).get
```

I also tried this:

```
val bytes = xml.toString.getBytes("utf-16le")
val body = AnyContentAsRaw(RawBuffer(bytes.length, bytes))
val headers = FakeHeaders(Seq(("Accept", Seq("text/xml")), ("Accept-Charset", Seq("utf-16")), ("Content-Type", Seq("text/xml"))))
val req = FakeRequest(PUT, "/process", headers, body)
route(req).get
```