liveBook · Manning

Range header

As explained in Go in Practice, Second Edition

The Range HTTP header specifies one or more byte ranges of a resource that a client wants to receive.

The Range HTTP header lets a client request selected bytes instead of downloading an entire resource. During a large-file download, recording the local file size and requesting bytes from that offset avoids restarting after a network timeout. section 11.1.2

Resume a timed-out download in Go

Create a GET request, inspect the destination file, and set `Range` when existing data is present: `req.Header.Set("Range", "bytes="+start+"-")`. Send the request with an HTTP client configured for a five-minute timeout, retry timed-out requests while retries remain, and append the resumed response to the local file. The surrounding program retries up to 100 times and reports the final byte count. A final hash check can strengthen integrity assurance.

How Go in Practice, Second Edition covers it

How deep it goes
Explains offset calculation, header construction, timeout configuration, and recursive retries without detailing server-side response handling.
Examples
Demonstrates resuming `file.zip` from its current size while downloading from a remote URL.
What it assumes
Assumes familiarity with local files, HTTP GET requests, network errors, and timeout detection.
What you can do after
Apply it via Go's HTTP client to resume downloads and limit wasted bandwidth after timeouts.
How it connects
Connects HTTP range requests with file downloads, network timeouts, retries, HTTP clients, and integrity checks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.