HTTP communication procedure network infrastructure

basic introduction

Here Insert Picture Description

The simplest HTTP communication process takes place at the client and the server between.

Client sends a request, the server responds to the request as shown in FIG.

The most important objective is the client sends a request for access to resources on the server. However, the client in order to obtain the resources they want to have to tell the location of the server resources (URI). Only tell the server resource location server to return to the client wants to end its resources.

Therefore, the client can not send a request to acquire resources, at the time of sending the request, the request to carry some data, such as location URI resource request a location server, and so on.

And these data is the message.

The message is a data carrier client and server data interaction

Packet data structure

Information for the HTTP protocol interaction is known as HTTP packets

HTTP message itself is composed of multiple rows of data strings of text

The HTTP packets can be divided into two parts

  1. 报文 neck
  2. The message body

And here, according to the intended use of HTTP packets can be divided into the following two

  1. Request message (HTTP client sending the request message)
  2. Response message (HTTP server in response to a request packet)

Request packet structure as shown below
Here Insert Picture Description
and the response message structure as shown below

Here Insert Picture Description

注:
首部字段:包含表示请求和响应的各种条件和数学的各类首部。
一般有4种首部:
1. 通用首部
2. 请求首部
3. 响应首部
4. 实体首部

Transfer process

HTTP communication process in order to improve the stability and efficiency of transmission during transmission, there are two means to achieve transmission speed increases

  1. Compression and transmission (content code)

    压缩传输是指将传输内容进行压缩,降低内容的字节大小,从而实现传输速率的提升
    由发送方将内容进行编码压缩,然后由接收端根据发送方发送报文的请求头对内容进行解码
    常见的压缩方法如下
    1. gzip
    2. compress
    3. deflate
    4. identity
    
  2. Compression transmission block

    分块压缩传输是指发送方将要传输的内容进行分块,然后每一块进行压缩,然后一块一块发送给接收端。
    接收端根据发送方发过来的HTTP报文判断该块是属于整体内容的哪一部分,并且判断此时发送方所要发送的内容是否已经结束。
    接收端在介绍块数据的同时,会同时将块数据进行解码,无需等到发送方将数据全部发送过来再解码
    

Different communication transmission HTTP content can be divided into the following two

  1. Simple string transmission (Text Transfer)
  2. Multipart Object Transfer (containing the contents of the file transfer, image, audio, binary data; + Text Transfer binary transmission)

Simple Text Transfer content just to become a string (perhaps add content compression operation) in HTTP packets.

Text and binary transmission + transmission type require special entities for transmission

在这里要提一下实体主体和报文主体的区别:
报文:是HTTP通信中的基本单位,由8位组字节流组成,通过HTTP进行传输
实体:作为请求或者响应的有效载荷数据被传输,其内容由实体首部和实体主体组成
HTTP报文的主体用于传输请求或响应的实体主体

In order to be able to transmit text + binary transfer, HTTP MINE mechanism according to realize the following objects multipart

  1. multipart / form-data (used when a web form file upload, web development in the more commonly used)
  2. multipart / byteranges (status code 206 response message comprising the content using a plurality of ranges)

HTTP in the communication process, it is possible to determine the content of the service to be returned by the end of three mechanisms

These three mechanisms are as follows

  1. Server-driven negotiation
服务端根据请求报文的报文头相关字段来判断应该返回给什么类型的资源
相关首部字段如下
1. Accept
2. Accept-Charset
3. Accept-Encoding
4. Accept-Language
5. Content-Language
  1. Client-driven negotiation
在客户端由客户选择自己所想要的资源
例如,在一个网站中,是想要英文版本的还是要中文版本的,则由用户手动切换语言,
然后通过JavaScript将用户所做出的选择发送给服务端,服务端根据请求报文返回相应资源。
然后客户端将收到的内容重新在客户端那边显示
  1. Transparent negotiation
服务端驱动协商 + 客户端驱动协商
Published 26 original articles · won praise 1 · views 1190

Guess you like

Origin blog.csdn.net/bleeding_sky/article/details/104545151