9

If the post is using "multipart/form-data" content-type, and each part could be a file or other content type.

If I want to use GZIP, should the GZIP apply to the entire post body of all parts altogether or could it be possible to choose some file use gzip content-encoding while some file don't.

Is there any standard for it or only common practice ?

Thanks

For example, can I add Content-Encoding:gzip at below 'file1' part

Host: localhost:8081 Connection: keep-alive Content-Length: 317 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36 Cache-Control: no-cache Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop Postman-Token: 7143164d-0da5-0e1d-112e-91f2a21c22c2 Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryPZAv0gGlJrA4ABu2 Accept: */* Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7 ------WebKitFormBoundaryPZAv0gGlJrA4ABu2 Content-Disposition: form-data; name="key1" value1 ------WebKitFormBoundaryPZAv0gGlJrA4ABu2 Content-Disposition: form-data; name="file1"; filename="sample_file.txt" Content-Type: text/plain Content-Encoding: gzip ---------------------------IS IT OK TO ADD GZIP HERE? This is a sample file content! ------WebKitFormBoundaryPZAv0gGlJrA4ABu2-- 

2 Answers 2

6

Either apply Content-Encoding compression to the whole message (end-to-end), or have the payload compressed on the transport layer, Transfer-Encoding (potentially hop-by-hop). What you can not do is compression on each part.

The multipart/form-data media type does not support any MIME header fields in parts other than Content-Type, Content-Disposition, and (in limited circumstances) Content-Transfer-Encoding. Other header fields MUST NOT be included and MUST be ignored.

Emphasis mine. Source: https://www.rfc-editor.org/rfc/rfc7578#section-4.8

Sign up to request clarification or add additional context in comments.

Comments

2

If you specify "Content-Encoding: gzip" in the HTTP response header section, it will apply to the full response.

I don't believe there's a way to apply compression to individual parts.

4 Comments

Thanks for your help, I added a http request in question, so it is not OK to add 'gzip' in above 'file1' part?
I believe Julian's answer is not correct. If you wanted gzip to apply to the full response/request, "Content-Encoding: gzip" would need to occur in the toplevel headers, not in the headers of a particular part. That said, I'm not certain whether there is an RFC on how to combine gzip with multipart requests/responses.
@tobias - that's what I actually intended to say.
@JulianReschke ah okay, that makes sense, we're on the same page then :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.