1

I have many small binary (protobuf) payloads that I want to send in a way that avoids CORS pre-flight requests.

This means I need to encode the data as one of the following

  • multipart/form-data
  • application/x-www-form-urlencoded
  • text/plain

The most efficient approach seems to be multipart/form-data, but I'm unsure where the overhead becomes inefficient for smaller payloads.

How can I determine the minimal payload size for multipart/form-data to be a logical option?

halfbit
  • 54,462
  • 46
  • 195
  • 426
  • http://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data seems relevant – sideshowbarker Dec 28 '16 at 01:40
  • http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean/28380690#28380690 makes an interesting claim: “even if we could send files with application/x-www-form-urlencoded, we wouldn't want to, because it is so inefficient… has a single byte boundary per field (&), but adds a linear overhead factor of 3x for every non-printable character… But for printable characters found in text fields, it does not matter and generates less overhead, so we just use it.” – sideshowbarker Dec 28 '16 at 01:51
  • That sounds as concise of a reason as any to leverage formdata encoding. I wonder what the minimum non ASCII data size needs to be in order for that quoted statement to still be true. (e.g it may be valid at 10K but not 1K) – halfbit Dec 28 '16 at 01:59
  • Right. Not sure but for the general case it seems better to just send the payload as the entity body of the request, which avoid all this. But that would trigger a preflight so I realize that wouldn’t solve the problem in this case. – sideshowbarker Dec 28 '16 at 04:44

0 Answers0