HTTP protocol basis and packet capture analysis

Engage in even more handy when performance testing is indispensable to bypass the agreement, the understanding of the basic knowledge, deep understanding of the mechanism or protocol, can make you engage in the implementation of performance testing.

Here we HTTP protocol and performance testing must master some analytical tools to share.

Key technology focus on share performance testing implementation process must master the tools. More details, please refer to the relevant books or HTTP RFC documents.

HTTP basic architecture

Here we use a simple flow chart to show the basic structure of the HTTP protocol, so that we first have a basic understanding.

Web Client can be browsers, search engines, robots, etc. all based on the HTTP protocol to initiate tool http request. Web Server may be able to resolve any of the HTTP request and returns the response to the Web Client service can be identified, a common apache, nginx, IIS web servers, and so on. Concentration is the essence, look at the most simple HTTP interaction diagrams:

 

HTTP packet structure

Request packet HTTP request line by the request, a request header, the request content and blank lines 4 parts.

As shown below:

Next, figure simple analysis:

Request line

, URL field, a protocol version field is composed of three parts, a request method field, separated by spaces therebetween. Commonly used methods requests: GET, POST, HEAD, PUT, DELETE, OPTIONS, TRACE, CONNECT.

Request header

Request header pairs, one pair for each behavior, between the key and value by a colon (:) is divided by the key / value. The main role of the head of the request for notifying the server about the client's request for information.

A typical request header are:

User-Agent: generating a browser-type request

Accept: the client can identify the list of content types in response; asterisk * range used by the packet type. * / * Represents a pharmaceutically all types, type / * Indicates that all subtypes of type type.

Accept-Language: Client acceptable natural language

Accept-Encoding: Client compression encoding format acceptable

Accept-Charset: acceptable character sets

Host: host name of the request, allowing multiple domain names to bind the same IP address

connection:连接方式(close或keeplive)

Cookie: 存储在客户端的扩展字段

空行

最后一个请求头之后就是空行,用于告诉服务端以下内容不再是请求头的内容了。

请求内容

请求内容主要用于POST请求,与POST请求方法配套的请求头一般有Content-Type(标识请求内容的类型)和Content-Length(标识请求内容的长度)

响应报文HTTP响应报文由状态行、响应头、空行和响应内容4个部分构成。

如下图所示:

下面对响应报文格式进行简要的分析说明:

状态行

由HTTP协议版本、状态码、状态码描述三部分构成,它们之间由空格隔开。

状态码由3位数字组成,第一位标识响应的类型,常用的5大类状态码如下:

1xx:表示服务器已接收了客户端的请求,客户端可以继续发送请求

2xx:表示服务器已成功接收到请求并进行处理

3xx:表示服务器要求客户端重定向

4xx:表示客户端的请求有非法内容

5xx:标识服务器未能正常处理客户端的请求而出现意外错误

常见状态码说明:

200 OK: 表示客户端请求成功

400 Bad Request: 表示客户端请求有语法错误,不能被服务器端解析

401 Unauthonzed: 表示请求未经授权,该状态码必须与WWW-Authenticate报文头一起使用

404 Not Found:请求的资源不存在,例如输入了错误的url

500 Internal Server Error: 表示服务器发生了不可预期的错误,导致无法完成客户端的请求

503 Service Unavailable:表示服务器当前不能处理客户端的请求,在一段时间后服务器可能恢复正常

响应头

一般情况下,响应头会包含以下,甚至更多的信息。

Location:服务器返回给客户端,用于重定向到新的位置

Server: 包含服务器用来处理请求的软件信息及版本信息

Vary:标识不可缓存的请求头列表

Connection: 连接方式。

对于请求端来讲:close是告诉服务端,断开连接,不用等待后续的求请了。keeplive则是告诉服务端,在完成本次请求的响应后,保持连接,等待本次连接后的后续请求。

对于响应端来讲:close表示连接已经关闭。keeplive则表示连接保持中,可以继续处理后续请求。Keep-Alive表示如果请求端保持连接,则该请求头部信息表明期望服务端保持连接多长时间(秒),例如300秒,应该这样写Keep-Alive: 300

空行

最后一个响应头之后就是空行,用于告诉请求端以下内容不再是响应头的内容了。

响应内容

服务端返回给请求端的文本信息。

https://baijiahao.baidu.com/s?id=1596966404370818881&wfr=spider&for=pc

 

Guess you like

Origin www.cnblogs.com/SRH151219/p/11073395.html