如果您已拥有资源,为什么ETag会设置为必须要求? [英] Why would ETags set to a MUST requirement if you already have the resource?

查看:145
本文介绍了如果您已拥有资源,为什么ETag会设置为必须要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要将ETag设置为必须要求级别?

Why would you set ETags to a "MUST requirement level"?

在ETag返回之前获取资源...

You obtains the resource before the ETags returned...

我正在开发一个项目,我是一个客户端,它向服务器发送HTTP请求,该服务器返回带有ETag的HTTP Cache-Control标头以缓存响应(在每个添加请求中,它与If-None-Match标头用于确定数据是否过时以及是否应该发出新请求)。在我当前的项目中,ETags参数使用条件GET体系结构,其具有RFC 2119中规定的MUST需求级别。

I'm working on a project where I am the client that sends HTTP requests to a server that returns an HTTP Cache-Control header with ETags to cache response (where in each addition request it gets compared to the If-None-Match header to determine if the data is stale and if a new request should be made). In my current project the ETags parameter is using the conditional GET architecture with the MUST requirement level as specified in RFC 2119.

必须这个词,或术语必需或SHALL,意味着该定义是规范的绝对要求。
我不明白使用MUST要求级别的条件GET的意图?根据我的理解,必须要求限制(正确吗?)提供给发出请求的客户端的资源,但是客户端(在本例中我)已经拥有来自第一个请求的资源。我可以继续获得相同的资源(或更新的更新资源),无论是否返回If-None-Match和ETag标题字段都可以获得。

MUST This word, or the terms "REQUIRED" or "SHALL", mean that the definition is an absolute requirement of the specification. I don't understand the intent of using a conditional GETwith the MUST requirement level? From my understanding the MUST requirement is there to limit (is that right?) the resources provided to the client that makes the request, however the client (me in this case) already has the resources from the first request. Where I can continue obtaining the same resource (or a fresher resource if it gets updated) as much as I want with or without returning the If-None-Match and ETag header fields.

如果不限制返回的资源,在这种情况下将其设置为MUST需求级别的目的是什么?除了能够缓存和限制对服务器的请求数量(我要求从客户端点查看,是的,我知道我可以缓存它,但为什么必须要求)?这不仅仅用于限制资源吗?

What would be the purpose of setting it to the MUST requirement level in this case if it's not limiting the resources returned, Aside from being able to cache and limiting the amount of requests to the server (Im asking from the client point of view, yes I know I can cache it but why the MUST requirement)? Isn't this only used for limiting resources?

所以基本上,如果我可以在有或没有资源的情况下获得资源,是不是要求这个必须要求不是必需的?我在这里遗漏了什么吗?

So basically, doesn't it make this MUST requirement not a requirement if I can obtain the resources with or without it? Am I missing something here?

我的问题不在于询问Etags,Cache-Control或If-None-Match标头的工作原理和方式。

My Question is not asking the what and how Etags, Cache-Control, or If-None-Match headers work.

提前致谢,欢呼!

推荐答案


为什么会这样如果你已经有资源,ETags设置为必须要求?

Why would ETags set to a MUST requirement if you already have the resource?

客户端必须使用条件GET来减少数据流量。 / p>

A client MUST use a conditional GET to reduce the data traffic.


除了能够缓存和限制对服务器的请求数量

Aside from being able to cache and limiting the amount of requests to the server

请求数保持不变,但传输的数据总数发生变化。

The number of requests stays the same, but the total number of data transferred changes.

在if-none-matched GET请求中使用 ETag (有条件的GET)

Using ETags in if-none-matched GET requests (conditional GET)


  1. 当您进行API调用时,响应头包含一个ETag,其值是API调用中返回的数据的哈希值。您存储此ETag值以用于下一个请求。

  2. 下次进行相同的API调用时,包括 If-None-Match 请求标头,其中包含从第一步开始存储的ETag值。


    • 如果数据未更改,则响应状态代码将为 304 - 未修改并且没有返回任何数据。

    • 如果自上次查询以来数据已更改,则会像往常一样使用新的ETag返回数据。游戏再次启动:您存储新的ETag值并将其用于后续请求。

  1. When you make a API call, the response header includes an ETag with a value that is the hash of the data returned in the API call. You store this ETag value for use in the next request.
  2. The next time you make the same API call, you include the If-None-Match request header with the ETag value stored from the first step.
    • If the data has not changed, the response status code will be 304 – Not Modified and no data is returned.
    • If the data has changed since the last query, the data is returned as usual with a new ETag. The game starts again: you store the new ETag value and use it for subsequent requests.

为什么?


  • 使用条件GET请求的主要原因是减少数据流量。


这不是仅用于限制资源吗?

Isn't this only used for limiting resources?

否...


  • 您可以在一个请求中向API请求多个资源。


    • (好吧,那也是通过保存其他请求来限制资源。)


    我可以在有或没有资源的情况下获得资源吗?

    I can obtain the resources with or without it?

    当你忽略必须使用条件GET然后(a)流量将增加和(b)您丢失来自服务器端的资源已更改指示。您必须在客户端实现比较处理:第二个请求的资源比第一个请求的资源更新。

    When you ignore the "MUST use conditional GET" then (a) the traffic will increase and (b) you lose the "resource has changed" indication coming from server-side. You would have to implement the comparison handling on client side: is the resource of the second request newer than the one from the first request.

    这篇关于如果您已拥有资源,为什么ETag会设置为必须要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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