processor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

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

type MultiplexedProcessor map[string]Processor

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/layer0-platform/webpackager/processor"
	"github.com/layer0-platform/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 Processor

type Processor interface {
	Process(resp *exchange.Response) error
}

Processor scans and maybe modifies the provided Response.

type SequentialProcessor

type SequentialProcessor []Processor

SequentialProcessor consists of a series of subprocessors.

func (SequentialProcessor) Process

func (sp SequentialProcessor) Process(resp *exchange.Response) error

Process invokes all subprocessors in order.

Process fails immediately when some subprocessor returns an error. The subsequent subprocessors will not run in such case.

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.

Jump to

Keyboard shortcuts

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