HTTP Range Requests

Introduction

HTTP is the way in which content and information is served on the World Wide Web from a web server to clients (e.g. your web browser). In order to get content from a website, your browser needs to make HTTP requests to the web server hosting the website and the server responds by serving the requested content.

Typically, the web browser will serve the entire file that a browser has requested. However, this may not be very practical in certain situations. For example, you are watching a streaming video or listening to a podcast on a website. After watching or listening for a few seconds, you decide to skip the first half of the video or podcast and jump to the final minute.

Using the conventional way of serving files to your browser, you won’t be able to skip to the final minute of the video in your browser. You will first need to download the entire file (which can take some time depending on the size of the file, the speed of your internet connection, and the speed of the server’s connection) before you can jump to any part of the video.

HTTP range requests take care of these problems by issuing byte-range requests.

What are byte-range requests?

Byte-range requests do not ask the web server to serve an entire file. Instead, it requests the server to only serve a specified portion of the file. For example, let’s assume that the video you wish to watch on a website contains a total of 10,000 bytes and you wish to only watch the last few seconds. Instead of requesting the server to send the entire file from the first byte to the 10,000th byte, your browser could make a byte-range request asking the web server to transfer from the 9,000th byte to the 10,000th byte.

To indicate the part that is required to the web server, the HTTP request header sent by your browser would include a line that looks something like this:

Range: bytes=9000-10000

Byte-range requests can also be broken into multiple different parts called multi-part ranges in the HTTP request header, which look something like this instead:

Range: bytes=0-499, 500-999, 1000-1499

In this request, instead of requesting for the entire range from 0-1,499, the byte-range request is divided into three parts to get the same data from the web server.

Benefits of byte-range requests

If you just want to watch a portion of a video on a website, it is really a waste of bandwidth to have to download the whole video file, especially if you are using cellular data plans with a monthly cap. From the web server’s perspective, it is also a waste of their bandwidth to serve you an entire hour-long video when all you need is just a minute of it.

In addition, multipart byte-range requests offer other benefits. An important benefit is that by splitting the request of a large byte-range into a series of smaller byte-ranges, if there is an error in transmission in one of the parts, only that part needs to be downloaded again. Had the range not been split into parts, the entire range would have to be re-downloaded.

What Are HTTP Range and Byte-Range Requests?

Also, by using multipart byte-range requests, file downloads can be paused and resumed. The browser can simply request from the web server only the remaining parts starting from the range where the download was stopped earlier. Multi-part range requests can also speed up downloads by allowing the web server to serve different smaller byte-range parts in parallel instead of sequentially serving the bytes specified in a single large byte range.

Glossary

HTTP

HTTP is a protocol used to connect to web servers by web browsers to request content to view. This is also used to transfer larger files, and is often used for software updates.