DEV Community

wget Resume 416: Diagnose and Recover From Range Errors

You run wget -c on a large ISO, expect it to pick up where the last attempt stopped, and instead get:

HTTP request sent, awaiting response... 416 Requested Range Not Satisfiable
The file is already fully retrieved; nothing to do.

Sometimes the command exits immediately with status 0. Sometimes it sits idle for a minute or more first.

In both cases the message is misleading: wget is inferring that your local file is complete, not proving it.

This tutorial reproduces the response against a local server you control, explains what the headers actually say, separates the four common causes, and shows how to recover without appending new bytes to an old partial file. It finishes with a preflight and postflight wrapper that checks range support, Content-Range, final size and checksum before you trust a resumed download.

How wget Resume Normally Works

wget -c (or --continue) looks at the size of the local file and asks the server to send the rest. On an HTTP server that supports byte ranges, the request looks like this:

GET /payload.bin HTTP/1.1
Host: example.com
Range: bytes=400000-

A server that supports ranges answers 206 Partial Content with a Content-Range header naming the byte interval and the complete resource length:

HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-Range: bytes 400000-1048575/1048576
Content-Length: 648576

For the command-level baseline - saving files, inspecting headers, and using -c in scripts - this guide to resuming interrupted downloads with wget -c walks through the normal flow.

The key point here is that a resume depends on three separate promises: the server advertises range support, it honors the requested start offset, and the bytes it sends belong to the same version of the file you already have. wget depends on the first two and cannot verify the third at all. MDN's HTTP range requests guide explains the 206 / Content-Range contract and how to probe a server.

When one of those promises breaks, the result is not always a clean error. It can be a 416, a full 200 response that restarts the download, or a 206 that appends mismatched bytes.

Build a Range-Capable Test Server

To see the failure modes without risking a real download, use a small Python server that implements byte ranges and returns a proper 416. Save this as range_server.py:

#!/usr/bin/env python3
"""range_server.py - a deliberately small Range-capable file server.
Usage: python3 range_server.py ROOT [PORT]
"""
import os
import re
import sys
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import unquote, urlsplit
ROOT = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else ".")
PORT = int(sys.argv[2]) if len(sys.argv) > 2 else 8000
RANGE_RE = re.compile(r"^bytes=(\d*)-(\d*)$")
class RangeHandler(BaseHTTPRequestHandler):
    protocol_version = "HTTP/1.1"
    def do_HEAD(self):
        self.serve(head_only=True)
    def do_GET(self):
        self.serve(head_only=False)
    def serve(self, head_only):
        rel = unquote(urlsplit(self.path).path).lstrip("/")
        path = os.path.abspath(os.path.join(ROOT, rel))
        if not path.startswith(ROOT + os.sep) or not os.path.isfile(path):
            self.send_error(404)
            return
        size = os.path.getsize(path)
        start, end, status = 0, size - 1, 200
        header = self.headers.get("Range")
        if header:
            match = RANGE_RE.match(header.strip())
            if not match:
                self.send_error(400, "Unsupported Range header")
                return
            first, last = match.groups()
            if first == "" and last == "":
                self.send_error(400, "Empty Range header")
                return
            if first == "":
                start = max(size - int(last), 0)
            else:
                start = int(first)
            if last:
                end = min(int(last), size - 1)
            if start >= size or start > end:
                self.send_response(416)
                self.send_header("Content-Range", f"bytes */{size}")
                self.send_header("Content-Length", "0")
                self.end_headers()
                return
            status = 206
        length = end - start + 1
        self.send_response(status)
        self.send_header("Accept-Ranges", "bytes")
        self.send_header("Content-Type", "application/octet-stream")
        self.send_header("Content-Length", str(length))
        if status == 206:
            self.send_header("Content-Range", f"bytes {start}-{end}/{size}")
        self.end_headers()
        if head_only:
            return
        with open(path, "rb") as source:
            source.seek(start)
            remaining = length
            while remaining > 0:
                chunk = source.read(min(65536, remaining))
                if not chunk:
                    break
                self.wfile.write(chunk)
                remaining -= len(chunk)
if __name__ == "__main__":
    ThreadingHTTPServer(("127.0.0.1", PORT), RangeHandler).serve_forever()

It answers a satisfiable range with 206 plus Content-Range, an unsatisfiable one with 416 plus Content-Range: bytes */SIZE, and includes Accept-Ranges: bytes on successful file responses.

Because it sends Content-Length: 0 with the 416, it will not reproduce the keep-alive stall described later; that requires a server that leaves the response body undelimited and holds the connection open.

Reproduce a 416 Response Step by Step

Set up a served directory and a separate download directory. Keeping them apart matters: if you serve and download into the same directory, wget will overwrite the source file you are trying to serve.

mkdir -p /tmp/wget416/srv /tmp/wget416/dl
head -c 1048576 /dev/urandom > /tmp/wget416/srv/payload.bin
python3 /path/to/range_server.py /tmp/wget416/srv 8000 &
cd /tmp/wget416/dl

First, download the file normally:

wget -c http://127.0.0.1:8000/payload.bin

Now truncate the local copy and resume it. This is the healthy path:

truncate -s 400000 payload.bin
wget -c http://127.0.0.1:8000/payload.bin

wget sends Range: bytes=400000-, the server answers 206 Partial Content, and the file grows back to 1,048,576 bytes.

You can inspect the same response without downloading the body by asking for that range with curl:

curl -s -D - -o /dev/null \
  -H 'Range: bytes=400000-' \
  http://127.0.0.1:8000/payload.bin | head -n 8
HTTP/1.1 206 Partial Content
Server: BaseHTTP/...
Date: ...
Accept-Ranges: bytes
Content-Type: application/octet-stream
Content-Length: 648576
Content-Range: bytes 400000-1048575/1048576

Now resume a file that is already complete:

wget -c http://127.0.0.1:8000/payload.bin
HTTP request sent, awaiting response... 416 Requested Range Not Satisfiable
The file is already fully retrieved; nothing to do.

Check the exit status:

echo $?

On affected wget versions this prints 0. That is the first trap: a script that only checks $? will treat the 416 as a successful download, even though wget never compared the file's contents with the server's.

To make the server state unambiguous, ask for a range that is deliberately past the end:

curl -s -D - -o /dev/null \
  -H 'Range: bytes=9999999-' \
  http://127.0.0.1:8000/payload.bin | head -n 8
HTTP/1.1 416 Requested Range Not Satisfiable
...
Content-Range: bytes */1048576
Content-Length: 0

That Content-Range: bytes */1048576 is the most useful line in the exchange. It says: none of your requested ranges overlap, and the resource is currently 1,048,576 bytes long.

What wget Resume 416 Really Means

RFC 9110 defines 416 Range Not Satisfiable as the response when none of the ranges in the request overlap the current extent of the resource, or when the server rejects the range set. For a byte-range request, the server should include a Content-Range field with an unsatisfied-range value: bytes */<current-length>.

That gives you a three-way test:

What you see What it means What to do 416 + Content-Range: bytes */N , local size = N The request started at or beyond the end of the resource. The local file is probably complete. Verify with a checksum before trusting it. 416 + Content-Range: bytes */N , local size ≠ N The local file is larger than the remote file, or the remote file shrank. Quarantine the local file and download fresh. 416 without Content-Range The server rejected the range but did not reveal the current length. Probe separately; do not assume the file is complete.

The exit status is not a reliable substitute for this analysis. A 2026 wget bug report documents a retry that ended in a 416 yet was reported to the caller as a successful fetch. Treat $? as one signal, not the verdict.

Also check whether the 416 came from the origin or from something in between. A proxy or CDN that mishandles Range can return a 416 even when the origin would have served a valid 206. Running the same probe directly against the origin, or reading the Server and Via headers, separates the two.

The Four Causes of a Failed Resume

Cause 1: The Local File Is Already Complete

This is the ordinary case. Your local file is 1,048,576 bytes, the remote file is 1,048,576 bytes, and wget asks for bytes=1048576-. The first byte position equals the resource length, so the range cannot overlap anything. The server returns 416, and wget prints its "already fully retrieved" message.

The right response is not to delete the file automatically. Compare the local size with the Content-Range total, then verify a published checksum:

stat -c '%s' payload.bin
curl -fsSL http://127.0.0.1:8000/payload.bin.sha256
sha256sum payload.bin

If the checksums match, you are done; the 416 was accurate. If there is no published checksum, size agreement is evidence but not proof. A file can be the right length and still be corrupt - for example, if a previous resume appended bytes from a different version of the file.

Cause 2: The Remote File Changed

This is the dangerous case. The remote file may have been rebuilt, replaced by a new release, or truncated. Two sub-cases matter.

The remote file shrank. Your local file is larger than the remote one, so the resume offset is beyond the end of the resource. The server returns 416 with a smaller total in Content-Range. An older Launchpad report shows exactly this: the local file was larger than the server's copy, wget printed "already fully retrieved," and it exited with status 0.

Recovery is to move the local file aside and download fresh. Do not simply truncate the local file to the new length, because the first N bytes may also have changed.

The remote file changed but stayed the same size. This is worse, because the server can return a perfectly valid-looking 206 for your offset. wget appends the new file's tail to the old file's head, and the final size can look correct. The content is a chimera.

The wget manual is explicit about this limitation: it has no way of verifying that the local file is really a valid prefix of the remote file, and using -c against a file that changed rather than grew produces a garbled file.

This is why checksum verification matters for resumable downloads of release artifacts, ISOs, and datasets. If the publisher provides a SHA-256 sidecar, compare it after every resume. If not, compare a strong ETag captured before and after the download, or fall back to a fresh download when you cannot establish identity.

Cause 3: The Server Ignores or Rejects Range

Not every server that accepts a Range header honors it. Some configurations disable byte ranges, some proxies strip the header, and some dynamic endpoints cannot seek. The result is usually a 200 OK with the entire file, not a 416.

The same wget manual notes that when a server does not support continued downloading, wget restarts the download from scratch and overwrites the existing file. That is safe for the file but wastes the partial download and can surprise a script that expected a resume.

A 416 can also come from a server that treats the range as invalid for reasons unrelated to your local file - for example, a range request on a zero-length resource, a malformed or multi-range request, or a server-side cap on the number of ranges. The diagnostic is the same: read Content-Range, and probe with a simple one-byte range.

curl -s -D - -o /dev/null -H 'Range: bytes=0-0' \
  http://127.0.0.1:8000/payload.bin | head -n 8

A 206 with Content-Range: bytes 0-0/1048576 proves the server honors a basic range. A 200 proves it ignored the header. A 416 on bytes=0-0 means the resource is empty or the server is rejecting ranges outright.

There is also a wget-specific wrinkle: some options cause wget to send a preliminary HEAD request, and older reports show -c adding a Range header to that HEAD request as well. A server can answer that HEAD with 416 even though the subsequent GET would have worked. This was reported as wget bug #60289 and closed as not reproducible on wget 1.21.2, so treat it as a historical explanation for odd logs rather than a current default. If you see a HEAD line in wget -d output carrying Range, check the version and the option combination before blaming the file.

Cause 4: Keep-Alive Stalls After 416

A 416 response can leave wget waiting instead of exiting. A bug-wget report from May 2023 describes exactly this with wget 1.21.3: the server sends 416, wget acknowledges it, both sides go silent for about 65 seconds, and then the server closes the connection. The reporter traced the wait to wget's attempt to skip a short response body that never arrived, and found that adding --no-http-keep-alive made the command finish immediately.

The mechanism is a mismatch in connection handling. With keep-alive, wget tries to read and discard any response body before reusing the socket. If a 416 arrives without a body that wget can delimit - no Content-Length, or chunked

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.