In HTTP1.1, Connection: keep-alive is used to keep long links because of performance issues caused by TCP three-way handshakes. The browser uses Content-Length to determine whether the data has been accepted or not to render the Content. Clients can disable long links by using the header field Connection:close.

If there is no content-Length field, the request will be in a pengding state. If the content-Length definition is inconsistent with the actual data Length, the data will be truncated or pengding.

Transfer-enconding: Chunk chunk coding rules:

  1. Each block contains two parts, a length header and a data block;

  2. The length header is a line of plain text ending in CRLF (carriage return newline, i.e. \r\n), with a hexadecimal number to indicate the length;

  3. The data block follows the length header and also ends with CRLF, but the data does not contain CRLF;

  4. The end is indicated by a block of length 0, i.e. “0\r\n\r\n”.

By setting this header, the browser correctly parses the data and displays it line by line.

Scope of the request

Range requests are not a required feature of a WEB server and may or may not be implemented. All servers must explicitly tell clients to support range requests by adding accept-Ranges :bytes to the header field. If it is not supported, you can add the header field Accept-ranges: None or do not return this header field.

Scope of a single

GET /z4d4kWk.jpg HTTP/1.1

Host: i.imgur.com

Range: bytes=0-1023

The server will return partial Content 206

HTTP/1.1 206 Partial Content Content-range: bytes 0-1023/146515 Content-Length: 1024… (binary content)

Multiple range request

GET /z4d4kWk.jpg HTTP/1.1

Host: i.imgur.com

Range: bytes=0-50, 100-150

The server returns 206 Partial Content status and Content-Type: multipart/ Byteranges; Boundary = 3D6b6a416f9b5 header, Content-Type: multipart/ Byteranges Indicates that the response has multiple Byteranges. Each part of byterange has its own centen-Type header and Content-range, and uses the boundary parameter to divide the body

HTTP/1.1 206 Partial Content

Content-Type: multipart/byteranges; boundary=3d6b6a416f9b5

Content-Length: 282 –3d6b6a416f9b5

Content-Type: text/html

Content-Range: bytes 0-50/1270

<html> <head> <title>Example Do

–3d6b6a416f9b5

Content-Type: text/html Content-Range: bytes 100-150/1270

eta http-equiv=”Content-type” content=”text/html; c

–3d6b6a416f9b5–

Conditional range request

With reference to MDN

What the server needs to do after receiving the Range field

1. Check whether the range is valid. If the range is invalid, a 416 status code is returned, indicating that the range cannot be processed. 206 Partial Content 3. Returns the Content-range headerCopy the code