http Advanced articles

MIME data types

1. text: text format that is readable data, we should be the most familiar with text / html, and represents the hypertext documents, in addition
there are plain text text / plain, stylesheet text / css and so on.
2. image: i.e. the image file, there are image / gif, image / jpeg, image / png like.
3. audio / video: audio and video data, such as audio / mpeg, video / mp4 the like.
4. application: data format is not fixed, may be text may also be binary, it must be interpreted by the upper layer application.
Common are application / json, application / javascript, application / pdf , etc. In addition, if you really do not
know what type of data is, as just said "black box", will be application / octet-stream, that is, two opaque
binary data.

Encoding formats Encoding type

1. gzip: GNU zip compression format, is the Internet's most popular compression formats;
2. the deflate: zlib (the deflate) compression format, second only to the popularity of gzip;
3. br: A new compression algorithm optimized specifically for HTTP (Brotli).

 

 

 

 

 

 

 

 

 Represents the browser you want to use most of the HTML file, the weight is 1, followed by the XML file, the weight is 0.9, and finally any data type, weight is 0.8. After the server receives the request header, it will calculate the weight, and then output HTML or XML priority according to the actual situation.

 

Transfer large files

etc. gzip compression algorithm usually only have better compression rates for text files, pictures, audio, video and other multimedia data itself is already highly compressed, then the process does not become small gzip

Transmission block

Transfer-Encoding: chunked "and" Content-Length "These two fields are mutually exclusive, that is to say the response message in these two fields can not appear at the same time, a response packet transmission is either known length, either unknown length

Download source package from GitHub, GitHub to send real-time compression in real time, rather than all at once and then sent a good compression, so the length of the body beginning unknown. Therefore, we must use the chunked encoding, the compression part, to send a portion of the length of this part is known, but the total length of the finished compression only be known. chunked encoding used in the "streaming" send and receive data, the data is typically generated on the fly, that is the dynamic data

Range request

Web server is not a necessary function can be achieved or may not be realized, so the server must be used in the response field ahead "Accept-Ranges: bytes" clearly inform the client: "I support the scope of the request."

Range dedicated HTTP header field range request, the format is "bytes = xy", where x and y are the range data bytes.

Application: Breakpoint download

Multiple pieces of data

This situation requires use of a special MIME type: "multipart / byteranges", indicating that the message body is composed of segments of the multi-byte sequence, and also with a parameter "boundary = xxx" given separation between the segments mark.

Long connection Connection: keep-alive

TCP connection is not closed for a long time, the server must save its state in memory, which takes up server resources. If you have a lot of free long hair is not even the only connection, it will soon run out of server resources, resulting in server can not provide services for users really need. On the client, you can add the request in advance "Connection: close" field, tell the server: "This communication after the connection is closed." Server sees this field, we know that the client should take the initiative to close the connection, so in response message also add in this field, calls the Socket API closes the TCP connection after sending.

The server usually do not take the initiative to close the connection, but also can use some strategies to get nginx example

keepalive_timeout long connection timeout provided

"The maximum number of connection requests keepalive_requests provided long transmittable

Blocking FIFO queue

 

 并发连接:是同时对一个域名发起多个长连接,用数量来解决质量的问题。

浏览器限制连接次数,那就域名分片,就多开几个域名,比如shard1.chrono.com、shard2.chrono.com,而这些域名都指向同一台服务器www.chrono.com

Cookie : 生存周期 Expires和Max-Age

在JS脚本里可以用document.cookie来读写Cookie数据,属性“HttpOnly”会告诉浏览器,此Cookie只能通过浏览器HTTP协议传输,禁止其他方式访问

SameSite”可以防范“跨站请求伪造”(XSRF)攻击,设置成“SameSite=Strict”可以严格限定Cookie不能随着跳转链接跨站发送

还有一个属性叫“Secure”,表示这个Cookie仅能用HTTPS协议加密传输,明文的HTTP协议会禁止发送。明文的HTTP协议会禁止发送。但Cookie本身不是加密的,浏览器里还是以明文的形式存在。

Guess you like

Origin www.cnblogs.com/autointerface/p/11941745.html