webpagereplay

package
v0.0.0-...-8f69b07 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func DecompressResponse

func DecompressResponse(resp *http.Response) error

Decompresses Response Body in place.

func MintDummyCertificate

func MintDummyCertificate(serverName string, rootCert *x509.Certificate, rootKey crypto.PrivateKey) ([]byte, string, error)

Mints a dummy server cert when the real one is not recorded.

func MintServerCert

func MintServerCert(serverName string, rootCert *x509.Certificate, rootKey crypto.PrivateKey) ([]byte, string, error)

Returns DER encoded server cert.

func NewRecordingProxy

func NewRecordingProxy(a *WritableArchive, scheme string, transformers []ResponseTransformer) http.Handler

NewRecordingProxy constructs an HTTP proxy that records responses into an archive. The proxy is listening for requests on a port that uses the given scheme (e.g., http, https).

func NewReplayingProxy

func NewReplayingProxy(a *Archive, scheme string, transformers []ResponseTransformer) http.Handler

NewReplayingProxy constructs an HTTP proxy that replays responses from an archive. The proxy is listening for requests on a port that uses the given scheme (e.g., http, https).

func RecordTLSConfig

func RecordTLSConfig(root tls.Certificate, w *WritableArchive) (*tls.Config, error)

Returns a TLS configuration that serves a server leaf cert fetched over the network on demand.

func ReplayTLSConfig

func ReplayTLSConfig(root tls.Certificate, a *Archive) (*tls.Config, error)

Returns a TLS configuration that serves a recorded server leaf cert signed by root CA.

Types

type Archive

type Archive struct {
	// Requests maps host(url) => url => []request.
	// The two-level mapping makes it easier to search for similar requests.
	// There may be multiple requests for a given URL.
	Requests map[string]map[string][]*ArchivedRequest
	// Maps host string to DER encoded certs.
	Certs map[string][]byte
	// Maps host string to the negotiated protocol. eg. "http/1.1" or "h2"
	// If absent, will default to "http/1.1".
	NegotiatedProtocol map[string]string
}

Archive contains an archive of requests. Immutable except when embedded in a WritableArchive. Fields are exported to enabled JSON encoding.

func OpenArchive

func OpenArchive(path string) (*Archive, error)

OpenArchive opens an archive file previously written by OpenWritableArchive.

func (*Archive) Edit

func (a *Archive) Edit(f func(req *http.Request, resp *http.Response) (*http.Request, *http.Response, error)) (*Archive, error)

Edit iterates over all requests in the archive. For each request, it calls f to edit the request. If f returns a nil pair, the request is deleted. The edited archive is returned, leaving the current archive is unchanged.

func (*Archive) FindHostTlsConfig

func (a *Archive) FindHostTlsConfig(host string) ([]byte, string, error)

Returns the der encoded cert and negotiated protocol.

func (*Archive) FindRequest

func (a *Archive) FindRequest(req *http.Request, scheme string) (*http.Request, *http.Response, error)

FindRequest searches for the given request in the archive. Returns ErrNotFound if the request could not be found. Does not consume req.Body. TODO: conditional requests

func (*Archive) ForEach

func (a *Archive) ForEach(f func(req *http.Request, resp *http.Response))

ForEach applies f to all requests in the archive.

func (*Archive) Serialize

func (a *Archive) Serialize(w io.Writer) error

Serialize serializes this archive to the given writer.

type ArchivedRequest

type ArchivedRequest struct {
	SerializedRequest  []byte
	SerializedResponse []byte // if empty, the request failed
}

ArchivedRequest contains a single request and its response. Immutable after creation.

type ConvertorConfig

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

func (*ConvertorConfig) Convert

func (r *ConvertorConfig) Convert(c *cli.Context)

func (*ConvertorConfig) Flags

func (cfg *ConvertorConfig) Flags() []cli.Flag

type Installer

type Installer struct {
	AndroidDeviceId string
	AdbBinaryPath   string
}

func (*Installer) AdbInstallRoot

func (i *Installer) AdbInstallRoot(certPath string) error

func (*Installer) AdbUninstallRoot

func (i *Installer) AdbUninstallRoot() error

func (*Installer) InstallRoot

func (i *Installer) InstallRoot(certFile string, keyFile string) error

TODO: Implement root CA installation for platforms other than Linux and Android.

func (*Installer) RemoveRoot

func (i *Installer) RemoveRoot()

type PushPromiseRule

type PushPromiseRule struct {
	// URL to push.
	URL string

	// Header for the request being simulated by this push. If empty, a default
	// set of headers are created by cloning the current request's headers and setting
	// "referer" to the URL of the current (pusher) request.
	Headers http.Header
}

PushPromiseRule is a rule that adds pushes into the response stream.

type ResponseTransformer

type ResponseTransformer interface {
	// Transform applies transformations to the response. for example, by updating
	// resp.Header or wrapping resp.Body. The transformer may inspect the request
	// but should not modify the request.
	Transform(req *http.Request, resp *http.Response)
}

ResponseTransformer is an interface for transforming HTTP responses.

func NewRuleBasedTransformer

func NewRuleBasedTransformer(filename string) (ResponseTransformer, error)

NewRuleBasedTransformer creates a transformer that is controlled by a rules file. Rules are specified as a JSON-encoded array of TransformerRule objects.

func NewScriptInjector

func NewScriptInjector(script []byte, replacements map[string]string) ResponseTransformer

NewScriptInjector constructs a transformer that injects the given script after the first <head>, <html>, or <!doctype html> tag. Statements in script must be ';' terminated. The script is lightly minified before injection.

func NewScriptInjectorFromFile

func NewScriptInjectorFromFile(filename string, replacements map[string]string) (ResponseTransformer, error)

NewScriptInjectorFromFile creates a script injector from a script stored in a file.

type TransformerRule

type TransformerRule struct {
	// How to match URLs: exactly one of URL and URLPattern must be specified.
	URL        string
	URLPattern string

	// Rules to apply to these URLs.
	ExtraHeaders http.Header       // inject these extra headers into the response
	Push         []PushPromiseRule // inject these HTTP/2 PUSH_PROMISE frames into the response
	// contains filtered or unexported fields
}

TransformerRule is a single JSON-encoded rule. Each rule matches either a specific URL (via URL) or a regexp pattern (via URLPattern).

type WritableArchive

type WritableArchive struct {
	Archive
	// contains filtered or unexported fields
}

WriteableArchive wraps an Archive with writable methods for recording. The file is not flushed until Close is called. All methods are thread-safe.

func OpenWritableArchive

func OpenWritableArchive(path string) (*WritableArchive, error)

OpenWritableArchive opens an archive file for writing. The output is gzipped JSON.

func (*WritableArchive) Close

func (a *WritableArchive) Close() error

Close flushes the the archive and closes the output file.

func (*WritableArchive) RecordRequest

func (a *WritableArchive) RecordRequest(scheme string, req *http.Request, resp *http.Response) error

RecordRequest records a request/response pair in the archive.

func (*WritableArchive) RecordTlsConfig

func (a *WritableArchive) RecordTlsConfig(host string, der_bytes []byte, negotiatedProtocol string)

RecordTlsConfig records the cert used and protocol negotiated for a host.

Jump to

Keyboard shortcuts

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