Documentation ¶
Overview ¶
Package processor defines the Processor interface.
Processors manipulate an exchange.Response to optimize the page loading, especially with privacy-preserving prefetch. The canonical example is to detect subresources from the payload (usually an HTML document) and add the Link headers so that they are preloaded together. Processors typically just manipulate the headers, but aggressive ones may also modify the payload.
Processors can also serve as checkers. Such Processors do not mutate the exchange.Response in any way. Instead they inspect the exchange.Response and report an error if the response does not meet some criteria, e.g. when the response has HTTP status code other than 200 (OK). The preverify package provides processors falling into this category.
This package also provides interfaces to combine multiple Processors and use them as a single Processor: see MultiplexedProcessor and SequentialProcessor for details.
The defaultproc package provides a processor that can be used out of the box.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MultiplexedProcessor ¶
MultiplexedProcessor is a map from media types to processors. The map keys are normalized to lowercase and do not include parameters (e.g. "text/html", not "Text/HTML" or "text/html; charset=utf-8").
Example ¶
package main import ( "github.com/eanavitarte/webpackager/processor" "github.com/eanavitarte/webpackager/processor/htmlproc" ) func main() { html := htmlproc.NewHTMLProcessor(htmlproc.Config{}) _ = processor.MultiplexedProcessor{ "text/html": html, "application/xhtml+xml": html, } }
Output:
func (MultiplexedProcessor) Process ¶
func (mp MultiplexedProcessor) Process(resp *exchange.Response) error
Process invokes the processor based on Content-Type of the response.
Process normalizes Content-Type to the media type without parameters, using mime.ParseMediaType, then looks up the processor in the map using the normalized media type as the key. Process does nothing when the map has no entry for the given media type.
type SequentialProcessor ¶
type SequentialProcessor []Processor
SequentialProcessor consists of a series of subprocessors.
Directories ¶
Path | Synopsis |
---|---|
Package commonproc implements processors applicable to any HTTP responses.
|
Package commonproc implements processors applicable to any HTTP responses. |
Package complexproc provides a factory of fully-featured processors, namely NewComprehensiveProcessor.
|
Package complexproc provides a factory of fully-featured processors, namely NewComprehensiveProcessor. |
Package htmlproc implements a Processor to process HTML documents.
|
Package htmlproc implements a Processor to process HTML documents. |
htmldoc
Package htmldoc provides interface to handle HTML documents.
|
Package htmldoc provides interface to handle HTML documents. |
htmltask
Package htmltask implements some optimization logic for HTML documents.
|
Package htmltask implements some optimization logic for HTML documents. |
Package preverify implements processors to verify that HTTP responses can be distributed as signed exchanges.
|
Package preverify implements processors to verify that HTTP responses can be distributed as signed exchanges. |