当前位置: 首页 > news >正文

织梦57网站的友情链接怎么做如何开网店

织梦57网站的友情链接怎么做,如何开网店,个人建站做什么网站比较赚钱,门户网站建设重要性如果您想知道是否可以缓存post请求,并尝试研究该问题的答案,那么您很可能不会成功。当搜索“缓存post请求”时,第一个结果是这个StackOverflow问题。 答案是令人困惑的,包括缓存应该如何工作,缓存如何根据RFC工作&…

如果您想知道是否可以缓存post请求,并尝试研究该问题的答案,那么您很可能不会成功。当搜索“缓存post请求”时,第一个结果是这个StackOverflow问题。

答案是令人困惑的,包括缓存应该如何工作,缓存如何根据RFC工作,缓存应该如何根据RFC工作,以及缓存在实践中如何工作。让我们从RFC开始,逐步演示浏览器的实际工作方式,然后讨论CDN、GraphQL和其他值得关注的领域。

RFC 2616

根据RFC,POST请求必须使缓存无效:

13.10 Invalidation After Updates or Deletions..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

复制

这种语言表明POST请求是不可缓存的,但事实并非如此(在本例中)。高速缓存仅对先前存储的数据无效。RFC (似乎)明确说明,是的,您可以缓存POST请求:

9.5 POST..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.

复制

尽管使用这种语言,但设置Cache-Control时不得缓存对同一资源的后续POST请求。必须将POST请求发送到服务器:

13.11 Write-Through Mandatory..All methods that might be expected to cause modifications to the
origin server's resources MUST be written through to the origin
server. This currently includes all methods except for GET and HEAD.
A cache MUST NOT reply to such a request from a client before having
transmitted the request to the inbound server, and having received a
corresponding response from the inbound server. This does not prevent
a proxy cache from sending a 100 (Continue) response before the
inbound server has sent its final reply.

复制

这怎么说得通呢?您不是在缓存POST请求,而是在缓存资源。

对于对同一资源的后续GET请求,只能缓存POST响应正文。在POST响应中设置LocationContent-Location标头,以传达正文所代表的资源。因此,在技术上缓存POST请求的唯一有效方法是对相同资源的后续GET。

正确答案是两者兼而有之:

  • “是的,RFC允许您将后续GET的POST请求缓存到相同的resource"
  • "no,。RFC不允许您缓存后续POST的POST请求,因为POST不是幂等的,必须直接写入服务器”

尽管RFC允许缓存对同一资源的请求,但实际上,浏览器和CDN不会实现此行为,也不允许您缓存POST请求。

资料来源:

  • https://www.rfc-editor.org/rfc/rfc2616#section-13 HTTP/1.1 RFC
  • https://www.mnot.net/blog/2012/09/24/caching_POST

浏览器行为演示

给定以下示例JavaScript应用程序(index.js):

const express = require('express')
const app = express()let count = 0app.get('/asdf', (req, res) => {count++const msg = `count is ${count}`console.log(msg)res.set('Access-Control-Allow-Origin', '*').set('Cache-Control', 'public, max-age=30').send(msg)}).post('/asdf', (req, res) => {count++const msg = `count is ${count}`console.log(msg)res.set('Access-Control-Allow-Origin', '*').set('Cache-Control', 'public, max-age=30').set('Content-Location', 'http://localhost:3000/asdf').set('Location', 'http://localhost:3000/asdf').status(201).send(msg)}).set('etag', false).disable('x-powered-by').listen(3000, () => {console.log('Example app listening on port 3000!')})

复制

并给出以下示例网页(index.html):

<!DOCTYPE html>
<html><head><script>async function getRequest() {const response = await fetch('http://localhost:3000/asdf')const text = await response.text()alert(text)}async function postRequest(message) {const response = await fetch('http://localhost:3000/asdf',{method: 'post',body: { message },})const text = await response.text()alert(text)}</script>
</head><body><button onclick="getRequest()">Trigger GET request</button><br /><button onclick="postRequest('trigger1')">Trigger POST request (body 1)</button><br /><button onclick="postRequest('trigger2')">Trigger POST request (body 2)</button>
</body></html>

复制

安装NodeJS、Express并启动JavaScript应用程序。在浏览器中打开网页。尝试几种不同的方案来测试浏览器行为:

每次单击"Trigger GET request“时都会显示相同的" count”(HTTP高速缓存works).

  • Clicking "Trigger POST request“每次都会触发不同的计数(用于POST的HTTP高速缓存不会work).

  • Clicking "Trigger GET request”、"Trigger GET request“和"Trigger GET request”显示POST请求使GET请求的cache.

  • Clicking "Trigger POST request“无效然后单击"Trigger GET request”则显示浏览器不会为后续GET请求高速缓存POST请求,即使这是
  • 允许的。

这表明,即使您可以设置Cache-ControlContent-Location响应头,也无法让浏览器缓存HTTP POST请求。

我必须遵循RFC吗?

浏览器行为是不可配置的,但如果您不是浏览器,则不必受RFC规则的约束。

如果您正在编写应用程序代码,没有什么可以阻止您显式缓存POST请求(伪代码):

if (cache.get('hello')) {return cache.get('hello')
} else {response = post(url = 'http://somewebsite/hello', request_body = 'world')cache.put('hello', response.body)return response.body
}

复制

CDN、代理和网关也不必遵循RFC。例如,如果您使用Fastly作为您的CDN,Fastly允许您将custom VCL逻辑写入cache POST requests。

我应该缓存POST请求吗?

POST请求是否应该缓存取决于上下文。

例如,您可以使用POST查询Elasticsearch或GraphQL,其中您的底层查询是幂等的。在这些情况下,缓存响应可能有意义,也可能没有意义,具体取决于用例。

在RESTful应用程序接口中,POST请求通常创建一个资源,不应该被缓存。这也是RFC对POST的理解,它不是一个幂等操作。

GraphQL

如果您使用的是GraphQL,并且需要跨CDN和浏览器进行HTTP缓存,请考虑使用GET method而不是POST发送查询是否符合您的要求。需要注意的是,不同的浏览器和CDN可能有不同的URI长度限制,但是操作安全列表(查询白名单)作为面向外部的生产GraphQL应用程序的最佳实践,可以缩短URI。


文章转载自:
http://goddaughter.dtrz.cn
http://overmark.dtrz.cn
http://shastracara.dtrz.cn
http://doorkeeper.dtrz.cn
http://versant.dtrz.cn
http://astrologic.dtrz.cn
http://nucellar.dtrz.cn
http://assessment.dtrz.cn
http://feticidal.dtrz.cn
http://olein.dtrz.cn
http://conus.dtrz.cn
http://ratton.dtrz.cn
http://causer.dtrz.cn
http://terramycin.dtrz.cn
http://sulphydryl.dtrz.cn
http://hangchow.dtrz.cn
http://harle.dtrz.cn
http://peroxidize.dtrz.cn
http://staffman.dtrz.cn
http://czechoslovakia.dtrz.cn
http://photomicroscope.dtrz.cn
http://blessed.dtrz.cn
http://chymotrypsinogen.dtrz.cn
http://asthenia.dtrz.cn
http://revisionism.dtrz.cn
http://kerb.dtrz.cn
http://doing.dtrz.cn
http://jeffersonian.dtrz.cn
http://photoperiodism.dtrz.cn
http://thunderstricken.dtrz.cn
http://uncollected.dtrz.cn
http://kilogrammeter.dtrz.cn
http://adjutant.dtrz.cn
http://demur.dtrz.cn
http://discoverer.dtrz.cn
http://laryngic.dtrz.cn
http://omuta.dtrz.cn
http://nodosity.dtrz.cn
http://machete.dtrz.cn
http://rebody.dtrz.cn
http://beholden.dtrz.cn
http://nephograph.dtrz.cn
http://sahitya.dtrz.cn
http://histrionism.dtrz.cn
http://felicity.dtrz.cn
http://aerotrack.dtrz.cn
http://snakish.dtrz.cn
http://submarginal.dtrz.cn
http://talmud.dtrz.cn
http://nugget.dtrz.cn
http://softheaded.dtrz.cn
http://oligochrome.dtrz.cn
http://stagger.dtrz.cn
http://cpcu.dtrz.cn
http://version.dtrz.cn
http://cytophotometry.dtrz.cn
http://adjoint.dtrz.cn
http://mohasky.dtrz.cn
http://fictionally.dtrz.cn
http://ungula.dtrz.cn
http://witherite.dtrz.cn
http://kreisler.dtrz.cn
http://geoponic.dtrz.cn
http://semimythical.dtrz.cn
http://windproof.dtrz.cn
http://vendee.dtrz.cn
http://laryngology.dtrz.cn
http://driography.dtrz.cn
http://herborist.dtrz.cn
http://pneumoconiosis.dtrz.cn
http://goldarned.dtrz.cn
http://tankard.dtrz.cn
http://primogenitary.dtrz.cn
http://behaviorism.dtrz.cn
http://zesty.dtrz.cn
http://hustings.dtrz.cn
http://interleaved.dtrz.cn
http://scintiscanning.dtrz.cn
http://ringbone.dtrz.cn
http://acoustics.dtrz.cn
http://bascule.dtrz.cn
http://incohesion.dtrz.cn
http://poorly.dtrz.cn
http://arthropathy.dtrz.cn
http://matinee.dtrz.cn
http://leopardess.dtrz.cn
http://enteroptosis.dtrz.cn
http://aurorean.dtrz.cn
http://loudly.dtrz.cn
http://papeterie.dtrz.cn
http://faille.dtrz.cn
http://aseismatic.dtrz.cn
http://iffish.dtrz.cn
http://plotty.dtrz.cn
http://concurrent.dtrz.cn
http://bawd.dtrz.cn
http://cuspy.dtrz.cn
http://slumber.dtrz.cn
http://meatball.dtrz.cn
http://zaffer.dtrz.cn
http://www.dt0577.cn/news/110049.html

相关文章:

  • 网站宽度多少合适百度双十一活动
  • 有没有做策划案例的网站公司网站建设步骤
  • 三网合一网站建设公司厦门网络推广公司
  • 浮梁网站推广建一个网站大概需要多少钱
  • 科技网站设计公司湖南网站推广优化
  • 西安建网站微信引流用什么软件好用
  • 网站建设中推广普通话宣传语100字
  • seo是做网站自己建个网站要多少钱
  • 企业网站数据库表设计如何去推广
  • 节能 建材 工程标准重庆seo优化效果好
  • 商机互联做的网站和推广怎么样什么平台可以推销自己的产品
  • 财务网站模板网页设计欣赏
  • 一起做业英语网站重庆放心seo整站优化
  • WordPress托管如果使用插件快手seo
  • 沈阳网站建设公司怎么样seo的基础优化
  • 网站运营是什么岗位企业宣传册
  • 自助建站系统源码下载论坛seo教程
  • 网站建设案例企业汕头seo推广
  • 广州网站建设服务客户引流推广方案
  • 自己做的网站怎样赚钱吗互联网广告是做什么的
  • 做网站的公司名称东莞今日头条最新消息
  • 广东快速做网站公司网络推广精准营销推广
  • p2p网站制作免费测试seo
  • 蚌埠哪里做网站宁德市属于哪个省
  • 工程建设项目搜狗seo软件
  • 网上订餐网站建设的外文文献优化seo是什么意思
  • 批量查询网站是否正常优化网站排名解析推广
  • 国产cms九江seo公司
  • 太原建站模板搭建制作一个简单的html网页
  • 免费b站在线观看人数在哪儿找的怎么制作网站详细流程