5. Evaluation

2 阅读2分钟

5. Evaluation

rfc 7232 5. Evaluation

check/precondition/methon的处理顺序

 Except when excluded below, a recipient cache or origin server MUST
   evaluate received request preconditions after it has successfully
   performed its normal request checks and just before it would perform
   the action associated with the request method.  A server MUST ignore
   all received preconditions if its response to the same request
   without those conditions would have been a status code other than a
   2xx (Successful) or 412 (Precondition Failed).  In other words,
   redirects and failures take precedence over the evaluation of
   preconditions in conditional requests.

当收到request时,origin server的处理优先级为:

  1. its normal request check(redirects and failures)(MUST 在2.之前)
  2. Precondition(MUST 在3.之前)
  3. method执行(If-x中定义了MUST NOT执行method的情况)

显然,要描述redirects and failures/Precondition/method的执行流程,rfc 中定义的上述3点远远不够。于是在不违反rfc定义的情况下手动补全一下 执行流程:

  1. normal check

    ok:->2.

    fail:执行对应fail操作

  2. Precondition

    false:-> 根据If-x+code定义决定返回status code/etag/header;body取决于服务器实现。

    true:-> 3.

  3. method

    返回的结果取决于没有precondition时执行同一个请求返回的结果

   A server that is not the origin server for the target resource and
   cannot act as a cache for requests on the target resource MUST NOT
   evaluate the conditional request header fields defined by this
   specification, and it MUST forward them if the request is forwarded,
   since the generating client intends that they be evaluated by a
   server that can provide a current representation.  Likewise, a server
   MUST ignore the conditional request header fields defined by this
   specification when received with a request method that does not
   involve the selection or modification of a selected representation,
   such as CONNECT, OPTIONS, or TRACE.

不进行evalutate的情况

  • 如果server不是origin server也不能作为cache,那它不能(MUST NOT)进行evaluate,并且必须(MUST)转发(forwarded)
  • server必须(MUST)忽略在本specification中被定义为选择(selection)和修改(modification)的conditional request header fields。 例如:CONNECT, OPTIONS, or TRACE(并不是全部)

如果要进行evalutate,除了要满足上述要求外,还需要满足在If-x的定义中的要求。例如If-Match定义了cache不能处理它。

扩展有关的内容

 Conditional request header fields that are defined by extensions to
   HTTP might place conditions on all recipients, on the state of the
   target resource in general, or on a group of resources.  For
   instance, the "If" header field in WebDAV can make a request
   conditional on various aspects of multiple resources, such as locks,
   if the recipient understands and implements that field ([RFC4918],
   Section 10.4).