filter

package
v0.0.0-...-928cf05 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2021 Google LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillCache

func FillCache(ctx context.Context, handle MediaFilterHandle, setter CacheSet) error

FillCache will tee the media it recieves into a cache, using the normalized request URL as the key. Supply a cache setter with the setter argument.

func FilterError

func FilterError(handle MediaFilterHandle, statusCode int, msg string, v ...interface{}) error

FilterError is the preferred way to return errors from filters.

func FilterIf

func FilterIf(ctx context.Context, handle MediaFilterHandle,
	condition func(http.Request) bool, filter MediaFilter) error

FilterIf will apply a filter if condition() == true; otherwise, it will apply NoOp.

func GZip

func GZip(ctx context.Context, handle MediaFilterHandle) error

GZip applies gzip encoding to the media.

This is an example of a streaming filter. This will use very little memory and add very little latency to responses.

func LogRequest

func LogRequest(ctx context.Context, handle MediaFilterHandle) error

LogRequest doesn't modify the request. It simply logs it.

func NoOp

func NoOp(ctx context.Context, handle MediaFilterHandle) error

NoOp does nothing to the media.

func PipelineCopy

func PipelineCopy(ctx context.Context, response http.ResponseWriter, input io.Reader, request *http.Request, pipeline Pipeline) error

Performs a copy of input to response, with filters applied to the input. func PipelineCopy(ctx context.Context, response http.ResponseWriter, input io.Reader, request *http.Request, pipeline Pipeline) (int64, error) {

Types

type CacheSet

type CacheSet func(string, []byte, time.Duration)

type MediaFilter

type MediaFilter func(context.Context, MediaFilterHandle) error

MediaFilter functions can transform bytes from input to output.

type MediaFilterHandle

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

MediaFilterHandle is a pair of input and output for the filter to read and write. Request and response are also included in case the filter needs to refer to or modify those.

type Pipeline

type Pipeline []MediaFilter

Pipeline is just a slice of MediaFilters. This alias is just here for semantics.

Jump to

Keyboard shortcuts

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