inject

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package inject gives the ability to copy data and inject a payload before a specified marker. In order to let the user respond to the change in length, the API is split into two parts - Sniff checks whether the marker occurs within a specified number of initial bytes, and Copy sends the data to the destination.

The package tries to avoid double-injecting a payload by checking whether the payload occurs within the first Within + len(Payload) bytes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopyInject

type CopyInject struct {
	// Number of initial bytes within which to search for marker
	Within int
	// Only inject in responses with this content type
	ContentType string
	// A marker, BEFORE which the payload is inserted
	Marker *regexp.Regexp
	// The payload to be inserted
	Payload []byte
}

CopyInject copies data, and injects a payload before a specified marker

func (*CopyInject) ServeTemplate

func (ci *CopyInject) ServeTemplate(statuscode int, w http.ResponseWriter, t *template.Template, data interface{}) error

ServeTemplate renders and serves a template to an http.ResponseWriter

func (*CopyInject) Sniff

func (ci *CopyInject) Sniff(src io.Reader, contentType string) (Injector, error)

Sniff reads the first SniffLen bytes of the source, and checks for the marker. Returns an Injector instance.

type Injector

type Injector interface {
	Copy(dst io.Writer) (int64, error)
	Extra() int
	Found() bool
}

Jump to

Keyboard shortcuts

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