What request header is used for resuming a large file download, and what will the server return if it does not support it?
The breakpoint resuming download of large attachments relies on which request header: it relies on the Range header within the request. The client specifies in the next request where it wants to start from, and if the server supports range requests, it uses 206 Partial Content to only return this segment; if the server does not support range requests, it will return what is the second question - it will simply ignore this request header and return the entire resource with a 200 status code. Understanding the reasons for the failure of breakpoint resuming is crucial in distinguishing between the two latter cases.
What do the three status codes mean?
In accordance with the protocol document: return 206 for valid range, where the server provides part of the content within the requested byte range; return 416 Range Not Satisfiable if the range is invalid (for example, if the start position exceeds the file length); servers that do not support range requests should ignore the header and return the entire resource with 200.
It is the third one that is most easily misjudged. The client sees 200 and thinks it is 'I didn't send the range request header', actually the server has explicitly expressed once 'I don't support'. The document also mentions that early download tools would look at the Accept-Ranges: none in the response header to主动关掉暂停与续传功能,but due to the 'ignoring range request header' itself has the same meaning, this kind of writing is now rare.
The sequence is therefore very clear: send a HEAD or OPTIONS request first, check if there is Accept-Ranges: bytes in the response; if there is, discuss resuming; if not or the value is none, it means that this link can only be re-downloaded in full.
The byte offset starts from zero, and the right end can be omitted
The range notation uses a closed interval, with both the start and end positions calculated in bytes, and counting starts from zero. There are three common ways: only giving the start position to indicate 'from here to the end of the file', giving a complete range to indicate an exact range, and giving a negative number to indicate 'just the last few bytes'.
A request header can contain multiple segments at the same time, and the server may return the document in multiple segments. However, for resuming, it is more worthwhile to make use of another property: when only a single segment byte range is specified in the request header, this header belongs to the cross-domain security list header under cross-domain scenarios, and cross-domain requests do not need to go through the preflight. This is exactly the combination commonly used by media segment access and downloader resuming - a single segment is easy to handle and will not result in an additional round trip due to cross-domain.
Two types of scenarios of large files on the site
The appearance of
Both types need to pay attention to the same thing: whether the range request is available depends on the layer that finally outputs the file. When the program generates the download response itself, write 206 and the relevant headers according to the specification; if there is a gateway or cache in front, it is necessary to confirm that this layer will not swallow the entire range request or return a 200 without interval information.
After modifying, it is recommended to verify three scenarios separately: a single segment request from the beginning, an invalid range exceeding the file length (should return 416), and a complete request to the same address (should return 200 and include Accept-Ranges: bytes). All three returns are correct; breakpoint continuation is only truly available.
Common questions
Question: Is it misconfigured if the return is 200?Answer: Not necessarily. Ignoring the header and returning the entire resource when range requests are not supported is a behavior allowed by the specification. In this case, you should switch to complete download or confirm which layer does not support it.
Why do I keep getting the entire file when resuming download?Mostly, it's because the intermediate layer has turned the range request into a complete request. It's more effective to check layer by layer whether the request header and 206 response are passed through than just changing the download logic.
Is it more economical to request multiple intervals at once?Multiple segments will introduce the cost of multiple document responses and parsing. In most cases, it is simpler and easier to directly connect across domains by processing the transfer by single segment intervals.