Documentation
¶
Overview ¶
Package httpchecksum provides an HTTP client for computing checksums of remote resources with optimizations for common hosting providers (S3, GitHub, raw.githubusercontent.com).
The client attempts to retrieve checksums without downloading full content when possible:
- AWS S3: Uses X-Amz-Checksum-Sha256 header
- GitHub Releases: Uses GitHub API to fetch asset digests
- raw.githubusercontent.com: Uses ETag header (SHA256)
- Other servers: Downloads and computes SHA256
The client also validates HTTP cache headers to detect volatile content that should not be pinned for reproducible builds.
Example usage:
client := httpchecksum.NewClient()
checksum, err := client.GetChecksum(ctx, "https://example.com/file.tar.gz")
if err != nil {
// Handle error
}
// checksum is in format "sha256:..."
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAuthError ¶
IsAuthError checks if an error is an authentication error
func IsVolatileContentError ¶
IsVolatileContentError checks if an error indicates volatile content
Types ¶
type ChecksumResult ¶
type ChecksumResult struct {
// Checksum is the SHA256 checksum in the format "sha256:..."
Checksum string
// Headers contains HTTP headers that should be included in the source policy
// These are the request headers that the response varies by (from the Vary header)
Headers map[string]string
}
ChecksumResult contains the checksum and metadata for an HTTP resource
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles HTTP checksum operations
func (*Client) GetChecksum ¶
GetChecksum fetches the SHA256 checksum for a URL It attempts to use server-provided checksums when available to avoid downloading the entire file
func (*Client) GetChecksumWithHeaders ¶
func (c *Client) GetChecksumWithHeaders(ctx context.Context, rawURL string) (*ChecksumResult, error)
GetChecksumWithHeaders fetches the SHA256 checksum for a URL along with relevant HTTP headers It attempts to use server-provided checksums when available to avoid downloading the entire file Returns headers that should be included in the source policy based on the Vary response header
func (*Client) WithProgressFactory ¶
func (c *Client) WithProgressFactory(factory ProgressWriterFactory) *Client
WithProgressFactory returns a copy of the client with progress reporting enabled The factory is called when a download starts, receiving the content length
type GitHubRelease ¶
type GitHubRelease struct {
Assets []GitHubReleaseAsset `json:"assets"`
}
GitHubRelease represents a release from the GitHub API
type GitHubReleaseAsset ¶
type GitHubReleaseAsset struct {
Name string `json:"name"`
Digest string `json:"digest"` // Available since June 2025
}
GitHubReleaseAsset represents a release asset from the GitHub API
type ProgressWriterFactory ¶
ProgressWriterFactory creates a progress writer for a download contentLength is the total size in bytes (-1 if unknown) The returned writer receives all downloaded bytes
type VolatileContentError ¶
VolatileContentError indicates an HTTP resource has caching headers that suggest the content changes frequently or should not be cached, making pinning unreliable.
func (*VolatileContentError) Error ¶
func (e *VolatileContentError) Error() string