javascript - How's file downloaded by the browser over HTTP - Stack Overflow

admin2025-04-08  0

I'm currently trying to understand precisely what happens when a browser downloads a file to desktop, specifically how many HTTP requests are used, how the process is different to just getting a resource like an image or script, etc. I'd be grateful if anyone laid out a process here starting from A browser sends HTTP request.

I'm currently trying to understand precisely what happens when a browser downloads a file to desktop, specifically how many HTTP requests are used, how the process is different to just getting a resource like an image or script, etc. I'd be grateful if anyone laid out a process here starting from A browser sends HTTP request.

Share Improve this question edited Oct 12, 2015 at 6:55 Max Koretskyi asked Oct 12, 2015 at 6:41 Max KoretskyiMax Koretskyi 106k68 gold badges353 silver badges516 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6
  1. A Browser sends an http request
  2. The server responds with the file to be downloaded, and adds some HTTP headers (which say that it's a file to be downloaded) usually along these lines: Content-Type: application/octet-stream Content-Disposition: attachment; filename="picture.png"
  3. The Browser then handles the response according to user settings (usually asks for permission before saving)

I know it's a bit of reading, but this is a good resource. Also, for a less intense introduction this helped me out quite a bit.

As to the number of HTTP requests used the answer is one. There is a TCP handshake done then the request is transmitted, after that the response is sent back. There is a little more involved if everything is over SSL/TLS, but that's all part of one HTTP request/response cycle.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744124283a232390.html

最新回复(0)