Skip to content
Andrea Lab

ANDREA LAB / BLOG

ETag and SHA-256 for preserving document versions

How to separate HTTP validation from file identity to reduce transfers and retain a verifiable history.

A technical library checks manufacturers’ manuals every night. One address may return a new edition without changing its URL. Other links may lead to the same file. The importer needs to recognize both cases to maintain a useful history.

A Python architecture can combine HTTP validators with a SHA-256 fingerprint calculated over the acquired file. The validator helps ask whether the source offers a different representation. The fingerprint identifies the bytes retained and passed to downstream analyzers.

Retain the validator with its context

When a source returns an ETag, the client can store it with the representation and use it in a later If-None-Match request. For a conditional GET, a 304 response indicates that the corresponding representation can be reused under that condition. HTTP defines weak and strong validators, so interpret the value using its protocol semantics. RFC 9110.

This synthetic exchange checks a machine manual.

GET /manuals/model-a.pdf HTTP/1.1
Host: manuals.example
If-None-Match: "edition-a"

HTTP/1.1 304 Not Modified
ETag: "edition-a"

An ETag belongs to a resource representation at that source. Retain the context required to request it again. If language or credentials affect the response, a URL-only key can mix different representations.

Calculate the identity of what you store

When a new body arrives, calculate SHA-256 over the bytes you will install in storage. Record any transformation performed before fingerprinting. Downstream processes can then verify the same object.

The library can use a hash-derived storage key. Two URLs returning exactly the same file can share that object while retaining independent source records. A URL whose content changes creates a new version relationship.

The fingerprint establishes content identity within the design, while provenance needs a record of its own. Keep the requested link, acquisition time, and response associated with the version. To explain where an extracted fact came from, the system needs to connect that evidence to specific bytes.

Check that the reusable copy exists

A row containing an ETag does not guarantee the file remains in storage. A retention policy may have expired it, or a local cache may have been lost. Before sending a condition to avoid transferring the body, check that the associated representation can be recovered.

If a 304 arrives and the copy is missing, the workflow needs explicit recovery. It can request the file again without that condition and acquire the full body within the job’s bounds. The catalog should distinguish a recorded version from one available for download.

Bind extraction to a version

When PDF extraction produces text, record the document fingerprint and extractor version. A software update may justify running analysis again even if the file remains unchanged.

Separate identifiers answer two questions. Which document changed, and which result changed when processing it? For the example manual, a new edition and an improved extractor can produce different text for reasons worth preserving.

Test four paths

Prepare a test source that returns new content, a 304, different content at the same URL, and identical bytes from two URLs. Then remove the local copy to check recovery.

The library needs to preserve provenance and reuse content that remains available. Separating HTTP validation, file identity, and extraction results lets each update explain what was checked, what was stored, and what was processed again.