206 Partial Content: An HTTP Status Code Indicating Partial Content Returned

スポンサーリンク
スポンサーリンク

About 206 Partial Content

Overview of 206 Partial Content

Returning Partial Resourceswith an HTTP Status Code

206 Partial Content

Overview The 206 Partial Content status code is used when a server returns only a portion of a resource in response to a client request. It is primarily used for range requests with the Range header, enabling partial data transfer.

Meaning The client’s request was successful, and the specified range of content has been returned.

When is 206 Partial Content Returned?

  • When requesting a specific range of a resource using the Range header
  • When downloading large resources in segments
  • When streaming services or media playback requires partial data

Examples of 206 Partial Content

Partial File Download

GET /large-file.zip HTTP/1.1  
Host: example.com  
Range: bytes=0-1023  

Response example:

HTTP/1.1 206 Partial Content  
Content-Range: bytes 0-1023/1048576  
Content-Type: application/zip  

[binary data for the first 1024 bytes]

Explanation: This example shows a client sending a request with the Range header, and the server returning the requested range of data (in this case, the first 1024 bytes). This method is effective for downloading large files in parts.

Streaming Video Playback

GET /video.mp4 HTTP/1.1  
Host: example.com  
Range: bytes=1048576-2097151  

Response example:

HTTP/1.1 206 Partial Content  
Content-Range: bytes 1048576-2097151/4194304  
Content-Type: video/mp4  

[binary data for the requested byte range]

Explanation: This example demonstrates a video player using the Range header to request a specific range of data, with the server returning the requested portion of the video file. This mechanism facilitates smooth seeking operations.

Points to Note

Considerations when using the 206 Partial Content status code:

  • Proper Content-Range Header Configuration
    Ensure the response includes the Content-Range header, specifying the range of data returned and the total size of the resource.
  • Validation of the Range
    If the client requests an invalid range (e.g., a range exceeding the resource’s size), the server must return a 416 Range Not Satisfiable status code.

Comparison with Related HTTP Status Codes

Here is an explanation of status codes related to 206 Partial Content:

  • 200 OK: Used when the request is successful, and the entire resource is returned.
  • 416 Range Not Satisfiable: Returned when the client requests an invalid range.

Understanding these differences helps in using the 206 status code appropriately.