httprewrite

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: BSD-3-Clause, GPL-3.0, MIT, + 1 more Imports: 14 Imported by: 0

Documentation

Overview

Package httprewrite provides utilities for rewriting HTTP responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendHTMLHeadContents

func AppendHTMLHeadContents(res *http.Response, appendWith []byte) error

AppendHTMLHeadContents allows to append the contents of the <head> tag in an HTTP text/html response.

On error, the response body is unchanged and the caller may proceed as if the function had not been called.

func BufferRewrite

func BufferRewrite(res *http.Response, processor func(src []byte) []byte) error

BufferRewrite reads and decodes the HTTP response body, applies a transformation to it using the provided processor function, and replaces the original body with the transformed version.

It automatically handles decompression and character set conversion to UTF-8. The processor receives the fully buffered, unpacked (decompressed and decoded) body as input and returns a modified byte slice.

func PrependHTMLBodyContents

func PrependHTMLBodyContents(res *http.Response, prependWith []byte) error

PrependHTMLBodyContents allows to prepend the contents of the <body> tag in an HTTP text/html response.

On error, the response body is unchanged and the caller may proceed as if the function had not been called.

func StreamRewrite

func StreamRewrite(res *http.Response, processor func(src io.ReadCloser, dst *io.PipeWriter)) error

StreamRewrite decodes the HTTP response body and passes it to the processor for transformation in a streaming fashion.

It automatically handles decompression and character set conversion to UTF-8. The processor receives the unpacked (decompressed and decoded) response body as an io.ReadCloser and writes the transformed output to the provided io.PipeWriter. The processor is responsible for closing both streams.

Types

This section is empty.

Jump to

Keyboard shortcuts

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