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.
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.
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.
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.
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.
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.
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.
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.
Index ¶
- func BlockRegex(ctx context.Context, handle MediaFilterHandle, regexes []*regexp.Regexp) error
- func FilterError(handle MediaFilterHandle, statusCode int, msg string, v ...interface{}) error
- func FilterIf(ctx context.Context, handle MediaFilterHandle, ...) error
- func GZip(ctx context.Context, handle MediaFilterHandle) error
- func Intercalate(ctx context.Context, handle MediaFilterHandle, separator string, ...) error
- func LogRequest(ctx context.Context, handle MediaFilterHandle) error
- func MyFilter(ctx context.Context, handle MediaFilterHandle) error
- func NoOp(ctx context.Context, handle MediaFilterHandle) error
- func PipelineCopy(ctx context.Context, response http.ResponseWriter, input io.Reader, ...) (int64, error)
- func ToLower(ctx context.Context, handle MediaFilterHandle) error
- func Translate(ctx context.Context, handle MediaFilterHandle, fromLang language.Tag, ...) error
- type CacheSet
- type MediaFilter
- type MediaFilterHandle
- type Pipeline
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockRegex ¶
BlockRegex will block responses that contain match any of the given regexes.
This function is a streaming function, and will not introduce significant TTFB latency. It will use about 4MB of RAM, give or take, for the scanning window. The scanning process ends up scanning all bytes twice, in order to detect matches that might span a stream chunk.
For example: window = [A B] window scans OK send A window = [B C] window scans OK send B and so on.
Partial responses may be sent, but any chunk with a regex match will not be sent, and the first one detected cancels the rest of the copy.
Patterns which may match more than 4MB of data are not supported; they will not error, but they simply will not be detected.
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 Intercalate ¶
func Intercalate(ctx context.Context, handle MediaFilterHandle, separator string, insertValue string) error
Intercalate will split the media, insert a value between elements, and return the concatenated result.
This function should be called from a lambda that applies desired values for intercalation, leaving only ctx and handle for use as a MediaFilter.
For example:
func(ctx context.Context, handle MediaFilterHandle) error { return Intercalate(ctx, handle, "\n", "f") },
This is an example of a store-and-forward filter, in that it loads the entire response to perform its transformation, so it will use memory at least equal to the source, and add its processing time to latency.
func LogRequest ¶
func LogRequest(ctx context.Context, handle MediaFilterHandle) error
LogRequest doesn't modify the request. It simply logs it.
func MyFilter ¶
func MyFilter(ctx context.Context, handle MediaFilterHandle) error
MyFilter is a place to put your code.
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) (int64, error)
Performs a copy of input to response, with filters applied to the input.
func ToLower ¶
func ToLower(ctx context.Context, handle MediaFilterHandle) error
ToLower applies bytes.ToLower 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 Translate ¶
func Translate(ctx context.Context, handle MediaFilterHandle, fromLang language.Tag, toLang language.Tag) error
Translate translates the media from one language to another.
This function should be called from a lambda that applies desired values for translation, leaving only ctx and handle for use as a MediaFilter.
For example:
func(ctx context.Context, handle MediaFilterHandle) error { return Translate(ctx, handle, language.English, language.Spanish, translate.HTML) },
This is an example of a store-and-forward filter, in that it loads the entire response to perform its transformation, so it will use memory at least equal to the source, and add its processing time to latency.
Types ¶
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.