# Allow（HTTP 头字段）

**Allow** 是一种 HTTP 响应头字段，用于列出目标资源所支持的请求方法，例如 `Allow: GET, HEAD, PUT`。用规范的话说，其目的严格限于告知接收方与该资源相关的有效请求方法；当源服务器以 405（方法不允许）状态码拒绝请求时，必须生成该字段。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 字段类型 | 响应头；列出目标资源支持的请求方法<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Allow)</sup> |
| 语法 | `Allow = #method`，即逗号分隔的方法名列表，例如 `Allow: GET, HEAD, PUT`<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 强制使用 | 源服务器在 405（方法不允许）响应中必须生成 Allow 头字段<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 可选使用 | 可以在任何其他响应中发送，常见于对 OPTIONS 请求的回复<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup><sup> • </sup><sup>[3](https://.dev/allow)</sup> |
| 空值 | 合法且有含义：该资源不允许任何方法，可能发生在资源因配置而被临时禁用时<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 代理规则 | 代理不得修改 Allow 头字段<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 注册状态 | 在 IANA HTTP 字段名注册表中为永久注册，引用 RFC 9110 第 10.2.1 节<sup>[4](https://www.iana.org/assignments/http-fields)</sup> |

## 目的与语义

该头字段描述的是目标资源，而非整个服务器。同一服务器上的不同资源往往支持不同的方法集合，因此该列表反映的是响应时刻该资源所接受的方法。<sup>[3](https://.dev/allow)</sup> 实际允许的方法集合由源服务器在每次请求时确定，并且可以动态变化，这正是该头字段属于建议性质而非契约的原因：它无法阻止客户端尝试其他方法，尽管客户端应当遵循其指示。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup><sup> • </sup><sup>[5](https://www.rfc-editor.org/rfc/rfc2616.html)</sup>

该列表是一组逗号分隔的方法令牌。空值并非错误；它表示该资源当前不允许任何方法，规范指出，如果资源因配置而被临时禁用，405 响应中可能出现这种情况。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

## 与 405 和 501 的关系

405（方法不允许）响应告知客户端：源服务器识别请求行中给出的方法，但目标资源无法处理该方法；此时源服务器必须在响应中包含 Allow 头字段，列出目标资源当前支持的方法。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> 典型响应如下：

```
HTTP/1.1 405 Method Not Allowed
Allow: GET, POST, HEAD
```

服务器所有者常出于安全原因禁用 TRACE 方法，向此类服务器发送 TRACE 请求正好会产生上述模式。<sup>[6](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/405)</sup>

两个相关错误码之间的区别很重要。服务器收到它不认识或未实现的方法时，以 501（未实现）响应，该响应不附带 Allow 要求；只有已识别但不支持的方法才会触发带该头字段的 405。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> 所有通用服务器都必须支持 GET 和 HEAD，但如果该方法不为特定资源所允许，这两个方法仍可能合法地导致 405。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

除非方法定义或显式缓存控制另有指示，405 响应可被启发式缓存，因此带有 Allow 列表的缓存 405 可被采用启发式过期策略的缓存复用。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

## 头字段出现的位置

除强制的 405 情形外，源服务器可以在任何响应中发送 Allow。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> 实践中，它最常出现在对 OPTIONS 请求的响应中，这类请求要求服务器描述资源可用的通信选项。<sup>[3](https://.dev/allow)</sup> 也曾观察到它出现在 201（已创建）响应中，用于指示新建资源上可用的方法，以及普通的 200 响应中。<sup>[3](https://.dev/allow)</sup>

## 实现行为

对 405 强制要求的支持因服务器软件而异。根据一份实践者指南，nginx 从不发出该头字段，因此由 nginx 应答的 405 到达时不带 Allow 字段；405 上缺失 Allow 往往表明响应者是代理而非其后的应用；相比之下，Apache 在 OPTIONS 和 405 响应中自动生成该头字段，根据资源支持的方法构建列表。<sup>[3](https://.dev/allow)</sup> 2017 年 nginx 邮件列表上的一次讨论同样指出，nginx 似乎没有 Allow 头字段。<sup>[7](https://mailman.nginx.org/pipermail/nginx/2017-August/054549.html)</sup>

Apache 管理员可以通过实验性的 `mod_allowmethods` 模块限制资源接受的方法，其 `AllowMethods` 指令接受区分大小写的方法列表（GET 与 HEAD 视为等同），且无法拒绝 TRACE，后者由 `TraceEnable` 单独控制。<sup>[8](https://d.apache.org/docs/current/en/mod/mod_allowmethods.html)</sup>

## 与 CORS 头字段的关系

Allow 有时会与 `Access-Control-Allow-Methods` 混淆，但二者面向不同的受众。Access-Control-Allow-Methods 是一种 CORS 响应头，告诉浏览器在预检之后跨源请求中可以使用哪些方法；无论该头字段内容如何，GET、HEAD 和 POST 始终作为 CORS 安全列表方法被允许。<sup>[9](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods)</sup> 当 OPTIONS 请求用作 CORS 预检时，响应通常带有 Access-Control-Allow-Methods，但一般省略 Allow，且这两个头字段不能互换：Allow 列出目标资源支持的请求方法，而 Access-Control-Allow-Methods 向浏览器指示 CORS 请求允许使用哪些方法。<sup>[3](https://.dev/allow)</sup><sup> • </sup><sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

## 规范历史

该字段自第一版 HTTP/1.1 规范起就已存在。RFC 2068（1997）将其定义为实体头字段，必须在 405 响应中出现；RFC 2616（1999）沿用了该定义，并增加了一项规定（后来被删除）：Allow 可随 PUT 请求发送，用于为新资源或修改后的资源推荐方法。<sup>[5](https://www.rfc-editor.org/rfc/rfc2616.html)</sup><sup> • </sup><sup>[10](https://www.rfc-editor.org/info/rfc2068/)</sup> RFC 7231（2014）将该字段重新表述为响应上下文字段，保留了相同的 405 强制规则以及空值和代理规则。<sup>[11](https://www.rfc-editor.org/rfc/rfc7231.html)</sup> 当前定义位于 RFC 9110《HTTP 语义》（2022 年 6 月）第 10.2.1 节，这也是 IANA 注册表中记录的引用。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup><sup> • </sup><sup>[4](https://www.iana.org/assignments/http-fields)</sup>

## References

1. [RFC 9110: HTTP Semantics, Section 10.2.1 (Allow), IETF](https://www.rfc-editor.org/rfc/rfc9110.html)
2. [Allow header - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Allow)
3. [Allow - Expert Guide to HTTP headers, http.dev](https://.dev/allow)
4. [Hypertext Transfer Protocol (HTTP) Field Name Registry, IANA](https://www.iana.org/assignments/http-fields)
5. [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1, Section 14.7, RFC Editor](https://www.rfc-editor.org/rfc/rfc2616.html)
6. [405 Method Not Allowed - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/405)
7. [HTTP/405, nginx mailing list (August 2017)](https://mailman.nginx.org/pipermail/nginx/2017-August/054549.html)
8. [mod_allowmethods - Apache HTTP Server Version 2.4](https://d.apache.org/docs/current/en/mod/mod_allowmethods.html)
9. [Access-Control-Allow-Methods header - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods)
10. [RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1, RFC Editor](https://www.rfc-editor.org/info/rfc2068/)
11. [RFC 7231: HTTP/1.1 Semantics and Content, Section 7.4.1, IETF](https://www.rfc-editor.org/rfc/rfc7231.html)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols › HTTP header fields

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/allow-http-header

English original: https://www.edgepedia.org/allow-http-header
