1

I've been looking at how to implement an API over HTTP that allows for online processing of the resource it returns. This resource could be a progressive JPEG, for example. In reading up on progressive JPEGs and how they are rendered in browsers I never see any mention of this requiring chunked transfer encoding to work. If I'm understanding things correctly I don't see how progressive JPEGs could be rendered before they are fully downloaded without the use of chunked transfer encoding. Is this correct?

Edit: To clarify why I think chunked encoding is needed if you don't use chunked encoding to GET a progressive JPEG then the browser or other application that sent the GET request for the JPEG wouldn't be passed the JPEG resource until it was fully received. With chunked encoding, on the other hand, as each chunk of the JPEG came in, the application (browser or otherwise) could render or do whatever with the portion of the JPEG that was received instead of not having anything to process until the full JPEG was downloaded.

2
  • I don't see why you'd need chunked encoding. Can you elaborate? Commented Oct 23, 2017 at 19:15
  • @JulianReschke I tried to clarify my thinking at the bottom of the OP. Commented Oct 25, 2017 at 15:09

1 Answer 1

2

the browser or other application that sent the GET request for the JPEG wouldn't be passed the JPEG resource until it was fully received

That's not true. Browsers can access resources they are downloading before the download completes.

In the end it's all received over a socket, and a proper abstraction layer lets the application code "stream" bytes from that socket as they come in in packets.

3
  • I understand if you use raw sockets but that doesn't seem like HTTP then at the application layer. What is the point of chunked encoding then? Commented Oct 26, 2017 at 11:18
  • 1
    A browser cuts through multiple layers of the OSI model, nobody forbids that. If a browser's programming model would only deal with completed HTTP responses, how would it show a download progress bar? As for why to use chunked, see What is the advantage to use chunked encoding?.
    – CodeCaster
    Commented Oct 26, 2017 at 11:22
  • 1
    Yeah, I just read this and I realized I was thinking about this the wrong way. I was confused by the notion that HTTP doesn't support "streaming" and misunderstood the difference/benefit with chunked encoding. Commented Oct 26, 2017 at 11:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.