playframework / playframework/play-ws
Can't configure Content-Type for Multipart Form Uploading
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 224
- Forks
- 92
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 28
Description
Play Version (2.5.x / etc)
2.5.10
API (Scala / Java / Neither / Both)
Java
Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)
Ubuntu 16.04.1 LTS
JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)
1.8.0_121
Expected Behavior
Following the spec set by RFC 2388 a POST with Content-Type=multipart/form-data should be able to support multiple content-types and character encoding in all of its parts.
Actual Behavior
https://www.playframework.com/documentation/2.5.x/JavaWS#Submitting-multipart/form-data
The play.mvc.Http.MultipartFormData.DataPart doesn't allow any sort of content-type configuration and it defaults to text/plain with no charset, which our back-end (JAX-RS) interprets as the default for text/plain: US-ASCII. RFC 1341
The play.mvc.MultipartFormatter.boundaryToContentType() beeing called uppon the format of a multipart Post also forces a content-type in the header without a charset configuration and therefore when using play.libs.ws.WSRequest.setContentType("multipart/form-data; charset=UTF-8") will make the request carry 2 Content-type entity headers.
#6928 seems like it had a similar problem.
Example Request sent by
POST /multipartform HTTP/1.1
Cache-Control: no-cache
Accept-Language: en
Content-Type: multipart/form-data; boundary=LK9jYpDyGz-nbNxWCA
Accept-Encoding: gzip,deflate
Transfer-Encoding: chunked
Host: 10.112.98.101:8010
Accept: /
User-Agent: AHC/2.0
161
--LK9jYpDyGz-nbNxWCA
Content-Disposition: form-data; name="request"
Content-Type: text/plain
{"stuff":null,"dummyDate":1487772284795,"action":null,"stuff":null}
6c
--LK9jYpDyGz-nbNxWCA
Content-Disposition: form-data; name="filename"
Content-Type: text/plain
SUM.csv
8d
--LK9jYpDyGz-nbNxWCA
Content-Disposition: form-data; name="data"; filename="SUM.csv"
Content-Type: multipart/form-data; charset=UTF-8
13
1;1;1;1;1;1;1;1;1;1
18
--LK9jYpDyGz-nbNxWCA--
0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with play.mvc.Http.MultipartFormData.DataPart and play.mvc.MultipartFormatter.boundaryToContentType(), then trace how WSRequest.setContentType() is applied to multipart requests. Done means multipart parts can specify their content types and the request does not emit duplicate Content-Type headers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, scala
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100