complexproc

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package complexproc provides a factory of fully-featured processors, namely NewComprehensiveProcessor. A ComprehensiveProcessor consists of prerequisite checkers, preprocessors, main processors, and postprocessors.

The prerequisite checkers inspect each resource and verify it is eligible for a signed exchange, provided by preverify.CheckPrerequisites.

The main processors include the key optimization logic and are defined on a per Content-Type basis. The default ones just include an HTML processor provided by the htmlproc package, applied to HTML (text/html) and XHTML (application/xhtml+xml). The caller can change the behavior of the HTML processor and/or add main processors for other media types through Config. It is also possible to override or disable the default processors.

The preprocessors and the postprocessors include the logic applied to all resources, before and after the main processors respectively. Some of them are considered to be essential and always included. The caller can specify additional preprocessors and postprocessors via Config; they are run after the essential ones.

Example (Customize)

This example constructs a new Processor that runs a custom HTMLTask and behaves otherwise the same as DefaultProcessor.

// Instantiate your custom HTMLTask.
yourTask := NewCustomHTMLTask()

// Have your HTMLTask run in the HTMLProcessor.
config := complexproc.Config{
	HTML: htmlproc.Config{
		TaskSet: append(htmltask.ConservativeTaskSet, yourTask),
	},
}

// Create the ComprehensiveProcessor.
_ = complexproc.NewComprehensiveProcessor(config)
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// EssentialPreprocessors contain always-run preprocessors.
	EssentialPreprocessors = processor.SequentialProcessor{
		commonproc.ExtractPreloadHeaders,
	}
	// EssentialPostprocessors contain always-run postprocessors.
	EssentialPostprocessors = processor.SequentialProcessor{
		commonproc.ContentTypeProcessor,
		commonproc.RemoveUncachedHeaders,
	}
)

These processors are always included in ComprehensiveProcessors.

View Source
var DefaultProcessor = NewComprehensiveProcessor(Config{})

DefaultProcessor is the processor used by webpackager.Packager by default.

Functions

func NewComprehensiveProcessor

func NewComprehensiveProcessor(config Config) processor.Processor

NewComprehensiveProcessor creates and initializes a new processor based on the provided Config.

Types

type Config

type Config struct {
	// Preverify is passed to preverify.CheckPrerequisites.
	Preverify preverify.Config

	// HTML is passed to htmlproc.NewHTMLProcessor.
	HTML htmlproc.Config

	// CustomMainProcessors is a map from media types to main processors.
	//
	// CustomMainProcessors takes the precedence over the default map.
	// When both maps contain the same keys, ComprehensiveProcessor runs
	// the processors from CustomMainProcessors instead of the default ones.
	//
	// CustomMainProcessors can have entries with a nil value. They disable
	// the default processors for the given media types.
	CustomMainProcessors processor.MultiplexedProcessor

	// CustomPreprocessors are run before the main processor.
	CustomPreprocessors processor.SequentialProcessor

	// CustomPostprocessors are run after the main processor.
	CustomPostprocessors processor.SequentialProcessor
}

Config customizes NewComprehensiveProcessor.

Jump to

Keyboard shortcuts

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