Skip to main content

5. Message Routing (消息路由)

5.1. Identifying a Target Resource (标识目标资源)

HTTP 请求的目标是一个"目标资源",客户端通过请求 URI 和 Host 头部字段的组合来标识它。

5.2. Connecting Inbound (入站连接)

确定目标 URI 后,客户端决定是否需要网络请求。如果需要,客户端将检查是否有可用的连接。

5.3. Request Target (请求目标)

request-target = origin-form
/ absolute-form
/ authority-form
/ asterisk-form

5.3.1. origin-form (源形式)

origin-form    = absolute-path [ "?" query ]

示例: GET /where?q=now HTTP/1.1

5.3.2. absolute-form (绝对形式)

absolute-form  = absolute-URI

示例: GET http://www.example.org/pub/WWW/TheProject.html HTTP/1.1

5.3.3. authority-form (授权形式)

authority-form = authority

仅用于 CONNECT: CONNECT www.example.com:80 HTTP/1.1

5.3.4. asterisk-form (星号形式)

asterisk-form  = "*"

仅用于 OPTIONS: OPTIONS * HTTP/1.1

5.4. Host Header Field (Host 头部字段)

Host = uri-host [ ":" port ]

关键规则:

  • 客户端必须 (MUST) 在所有 HTTP/1.1 请求中发送 Host 头部字段
  • 服务器必须 (MUST) 对缺少 Host 头部的 HTTP/1.1 请求响应 400 (Bad Request)

示例:

Host: www.example.org
Host: www.example.org:8080

5.5. Effective Request URI (有效请求 URI)

有效请求 URI 的构建规则取决于请求目标的形式和 Host 头部字段的值。

5.6. Associating a Response to a Request (关联响应与请求)

HTTP/1.1 中,响应与请求的关联通过连接上的顺序来确定。

5.7. Message Forwarding (消息转发)

5.7.1. Via Header Field (Via 头部字段)

Via = 1#( received-protocol RWS received-by [ RWS comment ] )

received-protocol = [ protocol-name "/" ] protocol-version
received-by = ( uri-host [ ":" port ] ) / pseudonym
pseudonym = token

Via 头部字段指示请求或响应消息路径上的中间协议和接收方。

示例:

Via: 1.0 fred, 1.1 p.example.net
Via: HTTP/1.1 GWA

5.7.2. Transformations (转换)

某些代理可能会转换消息内容。转换代理必须 (MUST) 添加 Warning: 214 头部字段。


✅ Section 5 完成