|
|
Posted on 11/27/2019 10:42:41 AM
|
|
|

The principle of breakpoint continuation is very simple, that is, the header of the HTTP request and reply message is different from the normal download. When requesting a document on a server in the normal way, the request made and the server received are as follows:
request header:
Cache-Control: no-cache
Connection: close
Pragma: no-cache
Accept: */*
Host: localhost response header:
200
Content-Type: application/octet-stream
Content-Disposition: attachment;FileName=time.pdf When the server supports breakpoint resumption, the request and response are as follows:
request header:
Cache-Control: no-cache
Connection: close
Pragma: no-cache
Accept: */*
Host: localhost
Range: bytes=15360- response header:
206
Content-Type: application/octet-stream
Content-Disposition: attachment;FileName=time.pdf The different parts of the two messages are marked with red sections. It can be seen: The Range header is used to identify the customer's desired download location. When the server's answer number is 200, it means that the download starts from the file header, and 206 means that the transfer starts from a specific location of the file. In other words, when supporting breakpoint resumption, you can start downloading from any part of the file, while the normal way can only download from the file header. To make the server support breakpoint resumption, the following problems need to be solved:
1。 If it is a resumption request, you need to obtain the file range required by the client. As you can see from the above analysis, when the client is transmitting a breakpoint, the Range field is added to the packet header, and you can determine whether it is a breakpoint transmission request as follows. string range = request. Headers["Range"]; bool isResume = string. IsNullOrEmpty(range);
2。 Respond correctly to the client to notify the client server that the endpoint is supported for continuation When sending a request for a breakpoint, the corresponding number for the client can be set as follows: response. StatusCode = 206;
3。 Deliver the right content that the client needs Delivering the correct content required by the client generally involves the following steps Obtain the client's file request range by analyzing the range. When a breakpoint is sent, the required length is shorter than the length of the file, so the correct response needs to be set. ContentLength64 property. Transfer the required content correctly Code example:
|
Previous:httplistener listens to get the POST request parametersNext:18 philosophical comics, all of whom are masters
|