网络协议 - ABNF表示的http协议
程序员文章站
2022-07-10 15:34:22
...
ABNF
使用ABNF描述http的请求和响应,需要几个要素:
- start-line
*
- header-filed
- CRLF
- SP
- message-body
- []
- OWS
1. start-line: request-line / status-line
2. * 代表一个或者多个
3. header-field 代表请求头/响应头字段
4. CRLF 代表换行/回车 在mac系统中,CR代表换行,linux系统中LF代表换行,在windows中CRLF代表换行
5. SP 代表空格
6. message-body 代表请求/响应内容
7. [] 代表可选,即可有可无
8. OWS 代表空格或者制表符
表现http的ABNF
HTTP-message = start-line*(head-field CRLF)CRLF[message-body]
* start-line = request-line/status-line
* request-line = method SP request-target SP HTTP-version CRLF
* status-line = HTTP-version SP status-code SP reason-phrase CRLF
* header-field = field-name:OWS field-value OWS
* OWS = (SP / HTAB)
* field-name = token
* field-value = *(field-content / obs-fold)
* message-body = *OCTET
//
OCTET 代表二进制数据
http request
// http request使用ABNF的表示方式
request-line *(head-field CRLF)CRLF [message-body]
// 示例
GET www.baidu.com HTTP/1.1
Remote Address: 182.61.200.7:443
Referrer Policy: unsafe-url
http response
// http response使用ABNF的表示形式
status-line *(head-field CRLF)CRLF [message-body]
// 示例
HTTP/1.1 400 Bad Request
Server: openresty/1.19.3.1
Date: Mon, 29 Mar 2021 15:09:39 GMT
Content-Type: text/html
Content-Length: 163
Connection: close
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>openresty/1.19.3.1</center>
</body>
</html>