Documentation
¶
Index ¶
- Variables
- func Scan(b []byte) []*proto.EsiFragment
- type InternalFetcherFunc
- type Option
- func WithAllowPrivateIPs(allow bool) Option
- func WithAllowPrivateIPsForAllowedHosts(allow bool) Option
- func WithAllowedHosts(hosts ...string) Option
- func WithDisableForwardCookies(disable bool) Option
- func WithHTTPClient(client *http.Client) Option
- func WithHeaderRequired(required bool) Option
- func WithIncludeErrorMarker(marker string) Option
- func WithInternalFetcher(fetcher InternalFetcherFunc) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxConcurrentRequests(limit int) Option
- func WithMaxDepth(depth uint32) Option
- func WithMaxResponseSize(size int64) Option
- func WithMaxTimeout(timeout time.Duration) Option
- func WithMetrics(reg prometheus.Registerer) Option
- func WithPreserveETag(preserve bool) Option
- type Processor
- func (p *Processor) AddSurrogateCapability(h http.Header, deviceToken string)
- func (p *Processor) CanProcess(h http.Header) bool
- func (p *Processor) ProcessFragments(ctx context.Context, parentReq *http.Request, parentBody []byte, ...) (*Result, error)
- func (p *Processor) ReconcileHeaders(h http.Header, res *Result)
- func (p *Processor) ShouldPreserveETag() bool
- type Result
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFallbackToHTTP is returned by an InternalFetcher to signal that the processor should resolve this include via outbound HTTP. ErrFallbackToHTTP = errors.New("esi: fallback to outbound http") )
Functions ¶
func Scan ¶
func Scan(b []byte) []*proto.EsiFragment
Scan inspects the HTML byte slice for ESI tags and extracts pre-compiled fragment metadata. It returns a slice of EsiFragment descriptors if any ESI directives exist, or nil if none are found.
Types ¶
type InternalFetcherFunc ¶
type InternalFetcherFunc func(ctx context.Context, targetPath string, r *http.Request) ([]byte, http.Header, error)
InternalFetcherFunc defines the signature for resolving in-process ESI includes.
func HandlerFetcher ¶
func HandlerFetcher(router http.Handler) InternalFetcherFunc
HandlerFetcher adapts any standard http.Handler into an InternalFetcherFunc for in-process subrequests.
type Option ¶
type Option func(*config)
Option configures ESI processor parameters.
func WithAllowPrivateIPs ¶
WithAllowPrivateIPs configures whether SSRF blocking permits dials to private/loopback CIDRs (default: false = blocked).
func WithAllowPrivateIPsForAllowedHosts ¶
WithAllowPrivateIPsForAllowedHosts permits private IPs specifically for explicitly allowed hosts.
func WithAllowedHosts ¶
WithAllowedHosts restricts external HTTP includes to matching domain patterns (default: empty = all public).
func WithDisableForwardCookies ¶
WithDisableForwardCookies configures whether Set-Cookie headers from subrequests are forwarded to the client (default: false = forwarded).
func WithHTTPClient ¶ added in v0.2.0
WithHTTPClient configures a custom http.Client for outbound fragment fetching.
func WithHeaderRequired ¶
WithHeaderRequired configures whether ESI is processed only when Surrogate-Control is present.
func WithIncludeErrorMarker ¶
WithIncludeErrorMarker configures an HTML placeholder rendered on unhandled fetch errors.
func WithInternalFetcher ¶
func WithInternalFetcher(fetcher InternalFetcherFunc) Option
WithInternalFetcher configures a custom in-process handler for resolving local fragment subrequests.
func WithLogger ¶ added in v0.2.0
WithLogger configures a custom slog.Logger for ESI processing.
func WithMaxConcurrentRequests ¶
WithMaxConcurrentRequests caps concurrent fragment fetch goroutines per document (default: 8).
func WithMaxDepth ¶
WithMaxDepth configures the maximum global recursion depth for nested includes (default: 3).
func WithMaxResponseSize ¶
WithMaxResponseSize caps the maximum allowed fragment body size in bytes (default: 10MB, 0 = unlimited).
func WithMaxTimeout ¶
WithMaxTimeout configures the maximum fetch timeout for resolving an include fragment (default: 30s).
func WithMetrics ¶ added in v0.2.0
func WithMetrics(reg prometheus.Registerer) Option
WithMetrics registers ESI telemetry collectors with the provided Prometheus Registerer.
func WithPreserveETag ¶ added in v0.2.0
WithPreserveETag configures whether downstream ETag (weakened) and Last-Modified are preserved on ESI documents (default: false = headers stripped, downstream 304 bypassed).
type Processor ¶ added in v0.2.0
type Processor struct {
// contains filtered or unexported fields
}
Processor orchestrates ESI fragment fetching, recursion handling, error fallbacks, and document splicing.
func NewProcessor ¶ added in v0.2.0
NewProcessor constructs a new ESI Processor from the provided options.
func (*Processor) AddSurrogateCapability ¶ added in v0.2.0
AddSurrogateCapability appends an ESI/1.0 capability token for the specified deviceToken to the request's Surrogate-Capability header (e.g. `deviceToken="ESI/1.0"`). If p is nil or h is nil, this is a no-op. If deviceToken is empty, "esi" is used.
func (*Processor) CanProcess ¶ added in v0.2.0
CanProcess reports whether the response headers satisfy ESI processing criteria. When WithHeaderRequired is false (default), it returns true; otherwise it verifies that Surrogate-Control contains "ESI/1.0".
func (*Processor) ProcessFragments ¶ added in v0.2.0
func (p *Processor) ProcessFragments( ctx context.Context, parentReq *http.Request, parentBody []byte, fragments []*proto.EsiFragment, ) (*Result, error)
ProcessFragments resolves all ESI fragments in parentBody, fetches includes concurrently, splices the results, and returns an assembled Result.
func (*Processor) ReconcileHeaders ¶ added in v0.2.0
ReconcileHeaders updates h in-place per ESI 1.0 (§3.2) and RFC 9110 specifications: - Removes Surrogate-Control header - Weakens or removes ETag and Last-Modified according to PreserveETag - Updates Content-Length if present to match the spliced body length - Appends fragment Set-Cookie headers from res
If the original headers must be preserved, call h.Clone() before passing.
func (*Processor) ShouldPreserveETag ¶ added in v0.2.0
ShouldPreserveETag reports whether downstream ETag (weakened) and Last-Modified headers are preserved.
type Result ¶ added in v0.2.0
type Result struct {
// contains filtered or unexported fields
}
Result contains the assembled document and metadata resulting from ESI processing. Callers must invoke Release when finished to return the underlying buffer to the memory pool.
func (*Result) Body ¶ added in v0.2.0
Body returns the assembled document byte slice. The slice is valid only until Release is called.