Documentation
¶
Overview ¶
Package httprewrite provides utilities for rewriting HTTP responses.
Index ¶
- func AppendHTMLHeadContents(res *http.Response, appendWith []byte) error
- func BufferRewrite(res *http.Response, processor func(src []byte) []byte) error
- func PrependHTMLBodyContents(res *http.Response, prependWith []byte) error
- func StreamRewrite(res *http.Response, processor func(src io.ReadCloser, dst *io.PipeWriter)) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendHTMLHeadContents ¶
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 ¶
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 ¶
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.