HTTP协议
应用级别协议
术语:
connection:两个应用间传输层虚拟回路
message: HTTP通信基本单元,由结构化的序列组成
request: 请求message
response: 应答message
resource: 网络数据对象或服务,通过URL进行识别
entity: request或response中作为负载的information
representation: response中entity,用来content negotiation
content negotiation: 一种机制,选择合适的representation
variant:一个resource可能有多个representation,每个representation称作variant
user agent: 用于初始化请求的client,通常是浏览器、编辑器、spider
origin server: resource保存或被创建的服务器
proxy:中间程序,同时扮演客户端、服务器
gateway:为其他server当作中转站,同proxy不同,gateway好像就是resource的origin server.
tunnel: 充当两个连接之间接力棒
upstream/downstream: 描述message的流程,所有的message从upstream流向downstream.
inbound/outbound: 针对message,引用request或response路径
请求= request method + URI + protocol version + (MIME-like message)
MIME-like message = modifiers + client information + body content
应答 = status line + MIME-like message
status line = protocol version + code
MIME-like message = server information + entity metainformation + entity-body content
proxy: 转发代理人,先接收请求,然后重写全部或部分message,将格式化后的message发往URI标识的server;
gateway: 接收代理人,在其他server上扮演一个layer,如果必要,将请求协议翻译为下层服务器协议;
tunnel: 在两个connection之间扮演replay点,不改变message。当两个connection之间需要返回firewall时使用
请求/应答流程
UA: user agent
O: Origin server
v: connectin
G: Gateway
A, B, C:代表三个中间程序
(简单流程)
request chain ------------------->UA---------------->v------------->O
| |
---------<----------------------|response chain
(复杂流程)
request chain ------------------->UA------>v------->A----->v----->B------v----->C-----v------>O
| |
|--------------------<-------------------------------------|response chain
(使用缓存)
request chain ------------------->UA------>v------->A----->v----->B------v----->C-----v------>O
| |
|--------------------<----------response chain
基本规则
OCTET = <any 8-bit sequence of data>
CHAR = <any US-ASCII character (octets 0 - 127)>
UPALPHA = <any US-ASCII uppercase letter "A".."Z">
LOALPHA = <any US-ASCII lowercase letter "a".."z">
ALPHA = UPALPHA | LOALPHA
DIGIT = <any US-ASCII digit "0".."9">
CTL = <any US-ASCII control character
(octets 0 - 31) and DEL (127)>
CR = <US-ASCII CR, carriage return (13)>
LF = <US-ASCII LF, linefeed (10)>
SP = <US-ASCII SP, space (32)>
HT = <US-ASCII HT, horizontal-tab (9)>
<"> = <US-ASCII double-quote mark (34)>
HTTP/1.1定义CR LF为所有协议元素的换行标记,除了entity-body;
CRLF = CR LF
HTTP/1.1头部字段可被包装为多行
TEXT = <any OCTET except CTLs, but including LWS>
HEX = "A" | "B" | "C" | "D" | "E" | "F"
| "a" | "b" | "c" | "d" | "e" | "f" | DIGIT
-----------------------------------------------------------------------------------------------------------------