Skip to content

feat(fileserver): add Content-Digest header support (RFC 9530) - #7937

Open
VedantMadane wants to merge 7 commits into
caddyserver:masterfrom
VedantMadane:feat-fileserver-content-digest
Open

feat(fileserver): add Content-Digest header support (RFC 9530)#7937
VedantMadane wants to merge 7 commits into
caddyserver:masterfrom
VedantMadane:feat-fileserver-content-digest

Conversation

@VedantMadane

Copy link
Copy Markdown

Summary

Fixes #7901

This PR adds optional RFC 9530 Content-Digest header generation to the ile_server handler for static file responses.

Details

  • Configurable via JSON content_digest array or Caddyfile content_digest / digest subdirectives.
  • Supports standard sha-256 and sha-512 algorithms.
  • Computes Content-Digest: sha-256=:...: / sha-512=:...: headers for static file responses.
  • Includes unit tests in staticfiles_test.go.

@CLAassistant

CLAassistant commented Aug 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@steadytao

steadytao commented Aug 11, 2026

Copy link
Copy Markdown
Member

Quick note. We need an AI assistance disclosure and CLA to be signed. although CLA assistant can be annoying sometimes, its fixed now :D

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always nice to align with RFCs but we need to do it to-the-letter when doing so. This should also have far more tests; verify exact digest values and add integration coverage for GET, HEAD, 304, ranges, precompressed responses and read/seek failures. In particular, a 206 digest must cover the selected representation data rather than the complete source file.

Comment thread modules/caddyhttp/fileserver/caddyfile.go Outdated
Comment thread modules/caddyhttp/fileserver/staticfiles.go Outdated
Comment thread modules/caddyhttp/fileserver/staticfiles.go Outdated
@steadytao steadytao added the feature ⚙️ New feature or request label Aug 11, 2026
@francislavoie

Copy link
Copy Markdown
Member

I think this can cause the sendfile optimization to be disabled when used (but only for an HTTP server, no TLS because we don't have kTLS yet).

When you pass a raw *os.File to a *net.TCPConn using io.Copy, Go triggers a zero-copy fast path, using the sendfile(2) syscall.

Should be noted in the docs.

@VedantMadane

Copy link
Copy Markdown
Author

Thank you @steadytao and @francislavoie for the detailed feedback!

I have updated the PR to address all your points:

  1. RFC 9530 Range (206 Partial Content) Support: Updated calculateContentDigest to parse the single range Range: bytes=start-end header. On 206 Partial Content responses, Content-Digest is now computed over the selected representation range bytes rather than the full source file, fully complying with RFC 9530 §2.
  2. Zero-Copy sendfile(2) Documentation: Added documentation notes in both struct doc comments and Caddyfile docs clarifying that enabling content_digest requires reading file bytes into memory to compute digests, which bypasses OS sendfile(2) zero-copy fast path on unencrypted HTTP connections.
  3. Comprehensive Integration Test Suite:
    • Added TestContentDigestExactValues asserting exact base64 multihash strings (sha-256 & sha-512).
    • Added TestContentDigestIntegration test suite covering GET (200), HEAD (200), 206 Partial Content Range, 304 Not Modified, and Precompressed (gzip sidecar) requests.
  4. CLA & AI Disclosure: CLA signed via CLA Assistant, and AI assistant pair-programming usage disclosed.

Validate and deduplicate content_digest algorithms in Caddyfile and
Provision. Return read/seek/reset errors from digest calculation so
failed digests cannot corrupt the response. Expand unit and integration
coverage for exact digests, ranges, precompressed responses, and
failure paths. Document sendfile impact in Caddyfile docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optional Content-Digest headers

4 participants