What is the flow of http request/response on file upload from browser?

20 Views Asked by At

What is the low-level flow of HTTP request/response between a browser and server while uploading/downloading a file?
And how does it handle memory?

Assumption
When sending a simple JSON data (content-type JSON), is the flow like this? :

  1. browser creates HTTP request object in memory
  2. browser populates the request with the request body
  3. browser sends the request as a whole to a server

Is this correct? Does browser store the whole request object in memory?

Question about upload
If so, how does the browser behave on uploading a file?

  • If user selects a file in a native pop-up (input type="file") in a multipart request, is the whole file loaded into memory, attached to a request; and once again send as a single data blob?
  • If not, is there a simple configuration (e.g. an input element parameter - input type="file" upload-strategy="stream"; or a header,...) which would tell the form to stream it directly from the client's storage?

I read about chunking, range headers, etc,..., but it got me more confused.

Question about download
Note that a colleague told me that on file downloads, a backend can firstly return a part of a HTTP response without a file (response status,...), and then actually stream the file content after it. Is this true? If so, how it's possible?

  • Does browser have a dedicated thread pool for downloading files, and when an http response comes with a content-disposition header, will it transfer the responsibility to the pool?
  • If so, is the file download pretty much a separate process? And it's not blocking the HTTP response, because it had returned earlier?

Question about connection timeouts
I guess that many HTTP clients have some sort of connection timeout settings, often set to small values like 1-3 seconds.
If so, how does browser handle a file upload that is taking longer for some reason (e.g. slow internet, large file,...)?
Does browser have such limits set to large numbers?

0

There are 0 best solutions below