206 HTTP: A Beginner’s Guide to Partial Content and Range Requests

If you develop or manage websites, then you’re likely familiar with the HTTP status code. This code is used to indicate the status of a request made to a web server, and can provide valuable information about what went wrong (or right) with that request. In this blog post, we’ll take a closer look at the 206 HTTP status code, explain what it means, and show you how to use it in your own applications. Let’s get started!

What is 206 Http Status Code

The 206 Http Status Code is a web server response code that indicates that the requested resource has been successfully retrieved, but that only a portion of it is being returned. This is often the case when a client makes the same request multiple times and only wants to receive new or updated information each time. In order to return the 206 Http Status Code, the web server must first determine which parts of the requested resource have been modified since the last request. Once this information has been determined, the web server can then return only those portions of the resource, instead of sending the entire resource again. This can save time and bandwidth for both the web server and the client.

How to use 206 Http Status Code

The 206 status code is not often used, but it can be very helpful in certain situations. This status code is most commonly used for range requests, which allow a client to request only part of a resource. For example, if a client wants to retrieve a large file but only needs the first few kilobytes, they can make a range request for that specific range. The server will then return only the requested range instead of the entire file.

See also  HTTP 414 URI Too Long: The Ultimate Guide to Understanding and Fixing This Error

206 Http Status Code example

Let’s say that a user wants to download a large image from a website. The website is calling an API to get the large file. In that case due to the size, the download process will take some time, so we split it with parts. 206 status codes can be used for multiple range requests, which allow a client to request multiple ranges at once. This can be useful when downloading large files in pieces or when streaming media files. You would specify byte range request with Content-Range: bytes 0-500/1234 where 1234 is the total length of the full file in bytes and the 0-500 is the partial image data. You can either specify only one range or multiple. If you are including multiple ranges of content, you can specify each range separated by a comma, like following example:

Browser request

GET /file/file1 HTTP/1.1 
Content-Range: bytes 0-500/1234, 1000-1500/1234

Server response

HTTP/1.1 206 Partial Content
Date: Wed, 2 Nov 2022 15:31:12 GMT
Last-Modified: Wed, 2 Nov 2022 11:31:12 GMT
Content-Length: 1741
Content-Type: multipart/byteranges; boundary=String_separator

--String_separator
Content-Type: application/pdf
Content-Range: bytes 234-639/8000

# the first range
--String_separator
Content-Type: application/pdf
Content-Range: bytes 4590-7999/8000

# the second range
--String_separator--

206 Http Status is a great way to improve the efficiency of your API by only returning the data that your clients need.

206 Http Status Code flow example

The key http headers in the communication between the clients (browser) and the server are the Accept-Ranges header, range header and content range header.

Browser requests the content. Server tells browser that the content can be requested partially with Accept-Ranges header. Accept-Ranges header represents the content that can be partially returned to browser. The value indicates the acceptable unit of each range request, usually is bytes in most situations.

See also  Password Manager Guide for Beginners
  • Browser resends the request, tells server the expecting range with Range header.

Head request with range http header:

GET /movie/movie1 HTTP/1.1
Range: bytes=0-1023
  • Server response
HTTP/1.1 206 Partial Content
Date: Fri, 14 Jan 2022 15:21:55 GMT

Content-Type: video/mp4

Content-Range: bytes 0-1023/2048

Content-Length: 1024

(Content...)
  • Browser resends second request, tells server the remaining expecting range with Range header.
GET /movie/movie1 HTTP/1.1
Range: bytes=1023-2048
  • Server response again
HTTP/1.1 206 Partial Content
Date: Fri, 14 Jan 2022 15:22:45 GMT
Content-Type: video/mp4
Content-Range: bytes 1024-2048/2048
Content-Length: 1024
(Content...)

Similar http statuses to 206 http status code

The 206 http status code is one of many HTTP status codes that are used to indicate the status of a request. There are several other status codes that have a similar meaning, including 200, 201, and 202. The 206 http status code is typically used to indicate that a request has been successful and that the requested information has been received. However, there are also other status codes that can be used to indicate success, depending on the context of the request. For example, if a request is made for a resource that does not exist, the 404 http status code may be used instead. Similarly, if a request is made for a resource that exists but is not accessible, the 403 http status code may be used. In general, the 206 http status code is just one of many possible indicators of success for a given request.

All HTTP status codes by categories

Leave a Reply

Your email address will not be published. Required fields are marked *