HTTP-Conditional Request

Source: Internet
Author: User
Tags ranges

When the HTTP request contains the header of the if-xxx style, the server will judge the attached condition, and the request will be executed only if the specified condition is true. Such requests have five headers, namely If-modified-since, If-unmodified-since, If-match, If-none-match and If-range.

If-modified-since

When the if-modified-since header is specified when using the GET method to request a resource on the server, if the resource has not been modified after the specified datetime, the server sends back a 304 not Modified response and does not echo the resource. If the object is modified, the server responds as if it were a non-conditional GET request.

A) The resource has not been modified since the specified date time

-H "If-modified-since:fri, 23:54:35 GMT" 304 Not Modified Date:tue, Sep 06:38:40 Gmtconnection:keep-alivecache-control:public,max-age=25920000accept-ranges:bytesetag : "7468b58329bce1:0"

b) The resource has been modified after the specified date time

-H "If-modified-since:fri, 03:00:00 GMT" OK Date:tue, Sep 06:43:02 gmtcontent-type:application/javascriptcontent-length:94020connection:keep-alivevary: accept-encodingcache-control:public,max-age=25920000Last-modified:fri, 03:06:57 GMT Accept-ranges:bytesetag: "7468b58329bce1:0"

If-unmodified-since

The role of the if-unmodified-since header is the opposite of the if-modified-since header. When the if-unmodified-since header is specified when using the GET method to request a resource on the server, if the resource is modified after the specified datetime, the server sends back a 412 precondition Failed response without echoing the resource. If the object has not been modified, the server responds as if it were a non-conditional GET request.

A) The resource has not been modified since the specified date time

-H "If-unmodified-since:fri, 23:54:35 GMT" OK Date:tue, Sep 06:49:51 gmtcontent-type:application/javascriptcontent-length:94020connection:keep-alivevary: accept-encodingcache-control:public,max-age=25920000Last-modified:fri, 03:06:57 GMT Accept-ranges:bytesetag: "7468b58329bce1:0"

b) The resource has been modified after the specified date time

-H "If-unmodified-since:fri, 03:00:00 GMT" 412 Precondition Failed Date:tue, Sep 06:50:12 Gmtcontent-type:text/htmlcontent-length:1333connection:keep-alivecache-control: public,max-age=25920000Last-modified:fri, 03:06:57 GMTaccept-ranges:bytesetag: "7468b58329bce1 : 0 "

If-match

When the If-match header is specified when using the GET method to request a resource on the server, the server does not execute the request until the ETAG value of the resource is the same as the specified value. Otherwise, the server echoes a 412 precondition Failed response. You can also use the asterisk (*) to specify the value of the If-match field, and the server ignores the value of the ETag as long as the resource exists to process the request.

A) The ETag value of the resource is consistent with the value specified by If-match

- h ' if-match: "7468b58329bce1:0" ' OK Date:tue, Sep 07:42:40 gmtcontent-type:application/javascriptcontent-length:94020connection:keep-alivevary: Accept-encodingcache-control:public,max-age=25920000last-modified:fri, 03:06:57 gmtaccept-ranges:bytes ETag: "7468b58329bce1:0"

b) The ETag value of the resource is inconsistent with the value specified by If-match

- h ' if-match: "7468b58329bce2:0" ' 412 Precondition Failed Date:tue, Sep 07:43:32 Gmtcontent-type:text/htmlcontent-length:1333connection:keep-alivecache-control: Public,max-age=25920000last-modified:fri, 03:06:57 gmtaccept-ranges:bytesETag: "7468b58329bce1:0" 

c) Use an asterisk (*) to specify If-match field values

- h ' if-match: * ' OK Date:tue, Sep 07:44:00 gmtcontent-type:application/javascriptcontent-length:94020connection:keep-alivevary: Accept-encodingcache-control:public,max-age=25920000last-modified:fri, 03:06:57 gmtaccept-ranges:bytes ETag: "7468b58329bce1:0"

If-none-match

The role of the If-none-match header is consistent with the If-match header. When the If-none-match header is specified when using the GET method to request a resource on the server, the server does not execute the request until the ETAG value of the resource is inconsistent with the specified value. Otherwise, the server echoes a 304 not Modified response.

A) The ETag value of the resource is consistent with the value specified by If-none-match

- h ' if-none-match: "7468b58329bce1:0" ' 304 Not Modified Date:tue, Sep 09:02:56 gmtconnection:keep-alivecache-control:public,max-age=25920000accept-ranges:bytes  ETag: "7468b58329bce1:0"

b) The ETag value of the resource is inconsistent with the value specified by If-none-match

- h ' if-none-match: "7468b58329bce2:0" ' OK Date:tue, Sep 09:04:31 gmtcontent-type:application/javascriptcontent-length:94020connection:keep-alivevary: Accept-encodingcache-control:public,max-age=25920000last-modified:fri, 03:06:57 gmtaccept-ranges:bytes ETag: "7468b58329bce1:0"

If-range

When the If-range header is specified when using the GET method to request a resource on the server, the resource's ETag value or time is processed as a range request if it matches the specified value. Conversely, the entire resource is returned.

HTTP-Conditional Request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.