How to escape Multipart HTTP boundary

2019-08-12 18:56发布

Let's say I'm sending a multipart request (or response). I need to choose a multipart boundary which does not appear in any of my payloads. However, my payloads are large binary files and I am streaming them to the destination. I want to avoid streaming them twice - once to scan for the boundary and one to stream out.

So my question is: is it possible to escape the boundary if it appears in the payload? If so, how?

2条回答
Anthone
2楼-- · 2019-08-12 19:00

No, it's not possible; you need to either scan, or live with potential failures.

查看更多
一夜七次
3楼-- · 2019-08-12 19:17

Don't Panic. Your boundary can be up to 70 characters long. If you go with that maximum and randomly generate it out of characters and numbers you'll have 62⁷⁰ possible combinations for each position in a file. Chance of having the same sequence of bytes in your binary files is so infinitesimal that it shouldn't bother your sleep at all

查看更多
登录 后发表回答