206
HTTPSUCCESSCommon2xx SuccessHIGH confidence

Partial Content

Production Risk

Low. This is essential for efficient media streaming and large file handling. A misconfigured server that does not support it may lead to poor performance.

What this means

The server is delivering only part of the resource due to a range header sent by the client. This is used for 'resumable' downloads or for fetching parts of a large file, such as a video, for streaming.

Why it happens
  1. 1A client requests a specific byte range of a large file using the 'Range' header.
  2. 2A video player streams content by requesting small chunks of the video file.
  3. 3A download manager resumes an interrupted download by requesting the remaining part of the file.
How to reproduce

A video player on a website buffers content by requesting the next segment of a video file.

trigger — this will error
trigger — this will error
GET /big-video.mp4 HTTP/1.1
Host: example.com
Range: bytes=1024-2048

expected output

HTTP/1.1 206 Partial Content

Fix

Support range requests on your server and handle 206 on the client

Support range requests on your server and handle 206 on the client
// Express — serve partial content for range requests
const fs = require('fs');

app.get('/video/:file', (req, res) => {
  const filePath = `./media/${req.params.file}`;
  const stat = fs.statSync(filePath);
  const rangeHeader = req.headers.range;

  if (rangeHeader) {
    const [start, end = stat.size - 1] = rangeHeader
      .replace('bytes=', '')
      .split('-')
      .map(Number);
    const chunkSize = end - start + 1;

    res.writeHead(206, {
      'Content-Range': `bytes ${start}-${end}/${stat.size}`,
      'Accept-Ranges': 'bytes',
      'Content-Length': chunkSize,
      'Content-Type': 'video/mp4',
    });
    fs.createReadStream(filePath, { start, end }).pipe(res);
  } else {
    res.writeHead(200, {
      'Accept-Ranges': 'bytes',
      'Content-Length': stat.size,
      'Content-Type': 'video/mp4',
    });
    fs.createReadStream(filePath).pipe(res);
  }
});

Why this works

To support 206, the server must advertise 'Accept-Ranges: bytes' and honour the Range header by streaming only the requested byte range. The response must include a Content-Range header ('bytes start-end/total') so the client knows where the chunk fits in the full file. Browsers and download managers use this to implement video seeking and resumable downloads automatically.

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All HTTP errors