netty/netty — pull request #2081 by igstan (2013-12-22 01:56:08+00:00)
Title: Allow an HTML5 encoder mode for HttpPostRequestEncoder

It looks like there are some HTTP application servers that are unable to handle multipart/mixed mode in HTTP requests. I've encountered this issue with a PHP script, but Django seems to have the [same problem][0]. I haven't searched for more cases because the HTML5 spec requires that browsers won't use multipart/mixed mode when uploading files under the same name:

> Note: In particular, this means that multiple files submitted as part of a single element will result in each file having its own field; the "sets of files" feature ("multipart/mixed") of RFC 2388 is not used.

Source (see Note section): http://www.w3.org/TR/html5/forms.html#multipart-form-data

Furthermore, RFC 2388 isn't very strict either when it comes to this encoding mode, using words such as "should" and "can" (emphasis mine):

> If multiple files are to be returned as the result of a single form entry, they **should** be represented as a "multipart/mixed" part embedded within the "multipart/form-data".

Source: http://tools.ietf.org/html/rfc2388#section-3

> If the value of a form field is a set of files rather than a single file, that value **can** be transferred together using the "multipart/mixed" format.

Source: http://tools.ietf.org/html/rfc2388#section-4.2

A few things I'm not so sure about:

- Maybe the encoder mode should be named differently, e.g. NO_MIXED_MODE
- Maybe instead of having the constructor accept a single `EncodeMode`, it should accept an `EnumSet`, so that non-mutually exclusive encodings can be used together

Let me know what you think and I'll adjust the pull request accordingly. Also, some pointers on how to write some unit tests for this would be appreciated.

[0]: https://code.djangoproject.com/ticket/12446