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, allowing the client to download a file at the same time that the thread is turned on, each of which downloads only a portion of the file, which is then combined into a complete file. Range also supports the continuation of a breakpoint, as long as the client records the downloaded portion of the file offset, you can ask the server to send the contents of the file from the breakpoint.
Nginx supports the range protocol very well, because the range protocol mainly adds some HTTP header processing, as well as offset processing when sending files. Nginx designed the HTTP filtering module, each request can be processed by a number of HTTP filtering modules, and the Http_range_header_filter module is used to handle the HTTP request header range section, it will parse the client request in the range header, 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 that points to the file according to the range protocol , so that only part of the content of a file is sent to the client.
In fact, it is very easy for us to support the range protocol, just set the ngx_http_request_t member Allow_ranges variable to 1 before sending it, and it will be done by the HTTP framework. eg
R->allow_ranges = 1;
In this way, we support multi-threaded download and breakpoint continuation.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Nginx support User multi-threaded download and breakpoint continuation