跳到主要内容

2. Architecture (架构)

HTTP 最初为 World Wide Web 架构创建, 后续演进为支持全球 hypertext system 的可扩展需求. HTTP 的术语和语法反映了该架构中的 resource, representation, message, connection 和 intermediary 等概念.

2.1 Client/Server Messaging (客户端/服务器消息)

HTTP 是无状态 request/response protocol, 通过可靠 transport 或 session-layer connection 交换 message. HTTP client 建立连接并发送 request. HTTP server 接受连接并发送 response.

Request message 以 request-line 开始, 后接 header field, 空行和可选 message body. Response message 以 status-line 开始, 后接 header field, 空行和可选 message body.

2.2 User Agents (用户代理)

User agent 是发起 request 的 client program, 包括 browser, crawler, command-line tool, mobile app 或后台自动化程序. 规范中要求向 user 报告错误时, 对非交互式程序来说可通过日志或错误控制台实现.

2.3 Intermediaries (中间方)

HTTP 允许通过 connection chain 使用 intermediary 满足 request. 常见 intermediary 包括 proxy, gateway 和 tunnel.

HTTP 定义为无状态协议. Server MUST NOT 假设同一 connection 上的两个 request 来自同一 user agent, 除非 connection 是安全且特定于该 agent 的.

2.4 Caches (缓存)

Cache 是先前 response message 的本地存储及其控制机制. Cache 可减少未来等效 request 的 latency 和 bandwidth consumption. HTTP caching 的详细规则由 RFC 7234 定义.

2.5 Conformance and Error Handling (一致性和错误处理)

实现若满足其实现的 protocol element 的所有要求, 即被认为 conformant. 本规范关注 wire protocol, 即 connection 上 HTTP message 的数据格式和时序.

Recipient SHOULD 拒绝或丢弃不安全 protocol element, 并在适当位置记录或报告错误. 自动恢复错误可能带来安全风险.

2.6 Versions (版本)

HTTP 使用 HTTP/<major>.<minor> 表示协议版本. Sender MUST 发送其符合的最高 HTTP version. Major version 变化表示 message syntax 不兼容变化. Minor version 变化表示新增 feature 但不改变 message syntax.

2.7 URI Schemes (URI 方案)

http URI scheme 用于通过 HTTP 定位 network resource, 默认端口为 80. https URI scheme 用于通过 TLS-protected HTTP connection 访问 resource, 默认端口为 443.