3.2. If-Range

1 阅读3分钟

3.2. If-Range

rfc 7233 3.2. If-Range

If-Range只能和GET一起使用

目前只找到If-Range和Range header一起使用的定义,而Range header只能和GET方法一起使用,所以我推断If-Range只能配合GET/Range header一起使用。

request中有If-Range但是没Range header时的处理

   A client MUST NOT generate an If-Range header field in a request that
   does not contain a Range header field.  A server MUST ignore an
   If-Range header field received in a request that does not contain a
   Range header field.

根据“If-Range”的语义,当 representation 没有变化时,需要用到请求中的Range header来看返回哪一部分。 如果没有Range Header,语义流程执行不下去。

上述节选就是在说

  • client 禁止(MUST NOT)产生这种有问题的request
  • server 必须(MUST)忽略这种有问题的request

当target resource不支持范围请求时

An origin server MUST ignore an If-Range header
   field received in a request for a target resource that does not
   support Range requests

如果一个target resource不支持Range request,那么它的请求中的If-Range header必须被server忽略。

UNDEFINED

如果一个target resource不支持Range request,服务器收到了它的request,这个请求包含Range header(不包含If-Range),此时server该如何处理?

取值

If-Range = entity-tag / HTTP-date

If-Range取值限制

   A client MUST NOT generate an If-Range header field containing an
   entity-tag that is marked as weak.  A client MUST NOT generate an
   If-Range header field containing an HTTP-date unless the client has
   no entity-tag for the corresponding representation and the date is a
   strong validator in the sense defined by Section 2.2.2 of [RFC7232].
  • 不能(MUST NOT)使用被标记为weak的etag作为If-Range的值
  • 不能(MUST NOT)使用HTTP-date,除非client没有etag并且这个HTTP-date是strong validator

If-Range的值的对比

 A server that evaluates an If-Range precondition MUST use the strong
   comparison function when comparing entity-tags (Section 2.3.2 of
   [RFC7232]) and MUST evaluate the condition as false if an HTTP-date
   validator is provided that is not a strong validator in the sense
   defined by Section 2.2.2 of [RFC7232].  A valid entity-tag can be
   distinguished from a valid HTTP-date by examining the first two
   characters for a DQUOTE.
  • 对比entity-tags时使用strong comparison function
  • evaluate结果为false当使用不满足作为强验证器的条件的HTTP-date做为验证器时
  • 当值为强验证器HTTP-date时,对比值是否完全一致:
Note that this comparison by exact match,
   including when the validator is an HTTP-date, differs from the
   "earlier than or equal to" comparison used when evaluating an
   If-Unmodified-Since conditional.

If-Range/Range header的处理

目前找到3处描述处理流程的地方

The Range header field is evaluated after evaluating the precondition
   header fields defined in [RFC7232], and only if the result in absence
   of the Range header field would be a 200 (OK) response.  In other
   words, Range is ignored when a conditional GET would result in a 304
   (Not Modified) response.
If the validator given in the If-Range header field matches the
   current validator for the selected representation of the target
   resource, then the server SHOULD process the Range header field as
   requested.  If the validator does not match, the server MUST ignore
   the Range header field.    
   5.  When the method is GET and both Range and If-Range are present,
       evaluate the If-Range precondition:

       *  if the validator matches and the Range specification is
          applicable to the selected representation, respond 206
          (Partial Content) [RFC7233]

   6.  Otherwise,

       *  all conditions are met, so perform the requested action and
          respond according to its success or failure.

处理顺序:

  • If-Range true -> Range Header(SHOULD) -> 206
  • If-Range false -> MUST ignore ->GET