Difference between multipart and chunked protocol?
Asked Answered
P

2

26

Can some experts explain the differences between the two? Is it true that chunked is a streaming protocol and multipart is not? What is the benefit of using multipart?

Pompei answered 2/12, 2013 at 18:3 Comment(1)
Just a guess, but I'd expect multipart to contain multiple separate parts, for multiple different contents etc - whereas chunked gives multiple chunks for the same entity. Worth looking into while you wait for someone more knowledgeable to answer :)Wilfredowilfrid
P
24

More intuitively,

Chunking is a way to send a single message from server to client, where the server doesn't have to wait for the entire response to be generated but can send pieces (chunks) as and when it is available. Now this happens at data transfer level and is oblivious to the client. Appropriately it is a 'Transfer-Encoding' type.

While Multi-part happens at the application level and is interpreted at the application logic level. Here the server is telling client that the content , even if it is one response body it has different logical parts and can be parsed accordingly. Again appropriately, this is a setting at 'Content-Type' as the clients ought to know it.

Given that transfer can be chunked independent of the content types, a multi-part http message can be transferred using chunked encoding by the server if need be.

Pickmeup answered 19/5, 2014 at 22:29 Comment(0)
E
13

Neither is a protocol. HTTP is the protocol. In fact, the P in HTTP stands for Protocol.

You can read more on chunked and multipart under Hypertext Transfer Protocol 1.1

Chunked is a transfer coding found in section 3.6 Transfer Codings.

Multipart is a media type found in section 3.7.2 Multipart Types a subsection of 3.7 Media Types.

Chunked also affects other aspects of the protocol such as the content-length as specified under 4.4 as chunked must be used when message length cannot be predetermined (mainly when delivering dynamic content).

From 14.41 (Transfer-Encoding header field)

The Transfer-Encoding general-header field indicates what (if any) type of transformation has been applied to the message body in order to safely transfer it between the sender and the recipient. This differs from the content-coding in that the transfer-coding is a property of the message, not of the entity.

Put more simply, chunking is how you transfer a block of data, while multipart is the shape of the data.

Ezar answered 2/12, 2013 at 19:14 Comment(2)
thanks Doog! so also seems like multiplart is for POST and chunked is for GET? can i draw that conclusion?Pompei
Unfortunately no. The key thing is that there is no body submitted in a GET request, but there are one or more bodies in the response. So you can receive multipart responses, even from a GET. Not all clients may support it, but it is part of the HTTP specifications. And again, chunked deals with the transfer, not the message shape. Typically you only post multipart when submitting files via a form (typically). Whether you POST or GET, the response may be multipart and/or chunked.Ezar

© 2022 - 2024 — McMap. All rights reserved.