Everything About HTTP 206 Partial Content Status and How to Use It

http status 206 partial content guide
10 November 2024

If you have been familiar with web development and working with servers and clients, you are likely already acquainted with the concept of HTTP status. One of the status codes that is commonly encountered in specific situations is status code 206 Partial Content. This state usually occurs when a client, such as a web browser, requests a portion of a resource from the server, and the server can only send that specific portion.

In general, this status code is for situations where you want to receive only a part of a file, such as a video or music, to conserve bandwidth. Suppose a video is currently being streamed and you want to jump to a specific segment of it. In this case, the client's browser can send an HTTP request to the server, and if the server uses status 206, there’s no need to download the entire file again.

However, which part of the file will the server send? This part is specified by specific headers in the HTTP request, which tell the server what portion of the file is needed. These headers are identified by the name Range. Operations with these headers are commonly used to download large files in chunks or even receive them from different servers.

Nevertheless, it should be noted that not all servers support status 206, and sometimes need to revert to using the full server for functionality as well. Additionally, status code 206 can help enhance loading speed by optimizing resources and reducing bandwidth consumption, resulting in a better user experience.

In general, using status code 206 can be more beneficial for users, for example in constructing multipart uploads or optimizing techniques for increasing page load speed, important issues that many web developers encounter frequently.

Example Code: HTTP Request with Status Code 206


  GET /video.mp4 HTTP/1.1
Host: example.com
Range: bytes=200-1000
HTTP/1.1 206 Partial Content
Content-Range: bytes 200-1000/67589

Line-by-Line Explanation of the Code

GET /video.mp4 HTTP/1.1: This line indicates that the client request (get data) is for the file video.mp4 on the server.
Host: example.com: This header specifies the hostname or domain of the server that the client wants to connect to.
Range: bytes=200-1000: This header indicates that the client wants to receive bytes 200 to 1000 of the file.
HTTP/1.1 206 Partial Content: The server response indicates that it has returned 206 Partial Content and recognized the client's request for part of the file.
Content-Range: bytes 200-1000/67589: In the response, the server specifies that it is sending bytes 200 to 1000 out of a total of 67589 bytes of the file.

FAQ

?

Why use status 206 Partial Content?

?

Can all servers support status 206?

?

What is the Range header?