fetch

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package fetch implements a read-through HTTPS artefact cache for direct downloads.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound indicates the upstream resource was not found.

Functions

This section is empty.

Types

type CachedResource

type CachedResource struct {
	UpstreamURL        string    `json:"upstream_url"`
	BlobHash           string    `json:"blob_hash"`
	Size               int64     `json:"size"`
	ContentType        string    `json:"content_type,omitempty"`
	ContentEncoding    string    `json:"content_encoding,omitempty"`
	ContentDisposition string    `json:"content_disposition,omitempty"`
	ETag               string    `json:"etag,omitempty"`
	LastModified       string    `json:"last_modified,omitempty"`
	CachedAt           time.Time `json:"cached_at"`
}

CachedResource stores metadata about a cached upstream download.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves cached direct-download artefacts.

func NewHandler

func NewHandler(index *Index, store store.Store, opts ...HandlerOption) *Handler

NewHandler creates a new fetch handler.

func (*Handler) ServeGitHubRelease

func (h *Handler) ServeGitHubRelease(w http.ResponseWriter, r *http.Request)

ServeGitHubRelease handles /github-release/{owner}/{repo}/releases/download/... requests.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles generic /fetch/{host}/{path...} requests.

type HandlerOption

type HandlerOption func(*Handler)

HandlerOption configures a Handler.

func WithAllowedHosts

func WithAllowedHosts(hosts []string) HandlerOption

WithAllowedHosts sets the allowlist for the generic /fetch route.

func WithDownloader

func WithDownloader(dl *download.Downloader) HandlerOption

WithDownloader sets the shared singleflight downloader.

func WithGitHubReleaseHost

func WithGitHubReleaseHost(host string) HandlerOption

WithGitHubReleaseHost overrides the host used by the /github-release route. This is mainly useful for tests.

func WithGitHubReleaseRedirectHosts

func WithGitHubReleaseRedirectHosts(hosts ...string) HandlerOption

WithGitHubReleaseRedirectHosts overrides the allowed redirect hosts for /github-release. This is mainly useful for tests.

func WithHTTPClient

func WithHTTPClient(client *http.Client) HandlerOption

WithHTTPClient sets the HTTP client used for upstream fetches.

func WithLogger

func WithLogger(logger *slog.Logger) HandlerOption

WithLogger sets the logger for the handler.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index manages the upstream URL -> blob mapping using metadb envelope storage.

func NewIndex

func NewIndex(resources *metadb.EnvelopeIndex) *Index

NewIndex creates a new fetch index backed by the given envelope index.

func (*Index) Delete

func (idx *Index) Delete(ctx context.Context, upstreamURL string) error

Delete removes a cached resource entry and decrements the blob refcount.

func (*Index) Get

func (idx *Index) Get(ctx context.Context, upstreamURL string) (*CachedResource, error)

Get retrieves a cached resource entry for the given upstream URL.

func (*Index) Put

func (idx *Index) Put(ctx context.Context, upstreamURL string, entry *CachedResource, opts metadb.PutOptions) error

Put stores a cached resource entry keyed by upstream URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL