The range protocol is defined in the RFC2616 specification, which gives a rule that allows the client to download only a portion of the full file in a single request, thus enabling the client to download a file while the threads are open, each of which downloads only a portion of the file, which is finally combined into a complete file. Range also supports continuation of breakpoints, which allows the server to send the contents of a file from a breakpoint as long as the client records the portion of the file offset that has been downloaded.
The Nginx support for the range protocol is very good because the range protocol mainly adds some HTTP header processing processes and the offset processing when sending files. Nginx designed the HTTP filtering module, each request can be processed by many HTTP filtering modules, and the Http_range_header_filter module is used to process the HTTP request header range, which resolves the range header in the client request. Finally, the Ngx_http_range_body_filter_module module is called when the HTTP response inclusion is sent, and the module modifies the File_pos and file_last members of the ngx_buf_t buffer to the file according to the range protocol To send only a portion of a file to the client in this implementation.
In fact, the support range protocol for us is very simple, only to be set before sending the NGX_HTTP_REQUEST_T member Allow_ranges variable is 1, then will be completed by the HTTP framework. eg
R->allow_ranges = 1;
In this way, we support multithreaded downloads and breakpoint continuation.