是否可以在 HTTP 中缓存 POST 方法? [英] Is it possible to cache POST methods in HTTP?

查看:46
本文介绍了是否可以在 HTTP 中缓存 POST 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有非常简单的缓存语义:如果参数相同(当然 URL 相同),那么它就成功了.那可能吗?推荐?

With very simple caching semantics: if the parameters are the same (and the URL is the same, of course), then it's a hit. Is that possible? Recommended?

推荐答案

对应的RFC 2616<9.5 节 (POST) 中的/a> 允许将响应缓存到 POST 消息,如果您使用适当的标头.

The corresponding RFC 2616 in section 9.5 (POST) allows the caching of the response to a POST message, if you use the appropriate headers.

对此方法的响应不可缓存,除非响应包括适当的 Cache-Control 或 Expires 头字段.然而,303(见其他)响应可用于引导用户代理到检索可缓存的资源.

Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.

请注意,相同的 RFC 在第 13 节(HTTP 中的缓存)中明确指出缓存必须在 POST 请求后使相应的实体无效.

Note that the same RFC states explicitly in section 13 (Caching in HTTP) that a cache must invalidate the corresponding entity after a POST request.

某些 HTTP 方法必须导致缓存以使实体无效.这是该实体所指的实体请求 URI,或按位置或内容位置标头(如果存在).这些方法是:

Some HTTP methods MUST cause a cache to invalidate an entity. This is either the entity referred to by the Request-URI, or by the Location or Content-Location headers (if present). These methods are:

  - PUT
  - DELETE
  - POST

我不清楚这些规范如何允许有意义的缓存.

It's not clear to me how these specifications can allow meaningful caching.

这也在 RFC 7231(第 4.3.3 节.),它废弃了 RFC 2616.

This is also reflected and further clarified in RFC 7231 (Section 4.3.3.), which obsoletes RFC 2616.

对 POST 请求的响应仅在包含时才可缓存
明确的新鲜度信息(参见 [RFC7234] 的第 4.2.1 节).
但是,POST 缓存并未广泛实现.对于源服务器希望客户端能够以一种以后可以重用的方式缓存 POST 的结果GET,源服务器可以发送一个 200 (OK) 响应,其中包含结果和具有相同值的 Content-Location 标头字段作为 POST 的有效请求 URI(第 3.1.4.2 节).

Responses to POST requests are only cacheable when they include
explicit freshness information (see Section 4.2.1 of [RFC7234]).
However, POST caching is not widely implemented. For cases where an origin server wishes the client to be able to cache the result of a POST in a way that can be reused by a later GET, the origin server MAY send a 200 (OK) response containing the result and a Content-Location header field that has the same value as the POST's effective request URI (Section 3.1.4.2).

据此,缓存 POST 的结果(如果服务器指示此能力)随后可以用作对同一 URI 的 GET 请求的结果.

According to this, the result of a cached POST (if this ability is indicated by the server) can be subsequently used for as the result of a GET request for the same URI.

这篇关于是否可以在 HTTP 中缓存 POST 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆