HTTP headers | Range

HTTP headers are used to pass additional information with HTTP request or response. HTTP range is an HTTP request header that is used to get part of a document from the server. If the server returns the part of the document, it uses the 206 (Partial Content) status code. If ranges are invalid status code used is 416 (Range Not Satisfiable) and the server uses status code 200 (OK) in case it ignores the range request.

Syntax:

  • To get whole document starting from a particular range
    Range: <unit>=<range-start>-
  • To request multiple parts
    Range: <unit>=<range-start>-<range-end>, <range-start>-<range-end>
  • To request specific end part of the document
    Range: <unit>=-<suffix-length>

Directives: There are four directives accepted by HTTP Range header, mentioned above and described below:



  • unit: It specifies the unit in which range is given. Generally bytes are used.
  • range-start: It is the integer specifying the starting of the document part.
  • range-end: It is the integer specifying the ending of the document part. It is an optional directive.
  • suffix-length: It is an integer indicating the end part of the document to be returned.

Examples:

  • To get first 100 bytes of the file
    Range: bytes=0-99
  • To get last 100 bytes of the file
    Range: bytes=-100
  • To request multiple ranges
    Range: bytes=0-99, 700-799

To check this Range in action go to Inspect Element -> Network check the request header for Range.

Supported Browsers: The browsers supported by HTTP header Range are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.