Documentation ¶
Index ¶
- Variables
- func CompressBody(ae string, uncompressed []byte) ([]byte, string, error)
- func DecompressResponse(resp *http.Response) error
- func MintDummyCertificate(serverName string, rootCert *x509.Certificate, rootKey crypto.PrivateKey) ([]byte, string, error)
- func MintServerCert(serverName string, rootCert *x509.Certificate, rootKey crypto.PrivateKey) ([]byte, string, error)
- func NewRecordingProxy(a *WritableArchive, scheme string, transformers []ResponseTransformer) http.Handler
- func NewReplayingProxy(a *Archive, scheme string, transformers []ResponseTransformer, quietMode bool) http.Handler
- func RecordTLSConfig(roots []tls.Certificate, w *WritableArchive) (*tls.Config, error)
- func ReplayTLSConfig(roots []tls.Certificate, a *Archive) (*tls.Config, error)
- type AddMode
- type Archive
- func (a *Archive) Add(method string, urlString string, mode AddMode) error
- func (a *Archive) Edit(...) (*Archive, error)
- func (a *Archive) FindHostTlsConfig(host string) ([]byte, string, error)
- func (a *Archive) FindRequest(req *http.Request) (*http.Request, *http.Response, error)
- func (a *Archive) ForEach(f func(req *http.Request, resp *http.Response) error) error
- func (a *Archive) Merge(other *Archive) error
- func (a *Archive) Serialize(w io.Writer) error
- func (a *Archive) StartNewReplaySession()
- func (a *Archive) Trim(trimMatch func(req *http.Request, resp *http.Response) (bool, error)) (*Archive, error)
- type ArchivedRequest
- type ConvertorConfig
- type Installer
- type PushPromiseRule
- type RequestMatch
- type ResponseTransformer
- type TransformerRule
- type WritableArchive
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
func CompressBody ¶
CompressBody reads a response body and compresses according to the given Accept-Encoding. The chosen compressed encoding is returned along with the compressed body.
func DecompressResponse ¶
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, quietMode bool) 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(roots []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 ¶
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 // The time seed that was used to initialize deterministic.js. DeterministicTimeSeedMs int64 // When an incoming request matches multiple recorded responses, whether to // serve the responses in the chronological sequence in which wpr_go // recorded them. ServeResponseInChronologicalSequence bool // Records the current session id. // Archive can serve responses in chronological order. If a client wants to // reset the Archive to serve responses from the start, the client may do so // by incrementing its session id. CurrentSessionId uint32 // If an incoming URL doesn't exactly match an entry in the archive, // skip fuzzy matching and return nothing. DisableFuzzyURLMatching bool }
Archive contains an archive of requests. Immutable except when embedded in a WritableArchive. Fields are exported to enabled JSON encoding.
func OpenArchive ¶
OpenArchive opens an archive file previously written by OpenWritableArchive.
func (*Archive) Edit ¶
func (a *Archive) Edit(edit 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 ¶
Returns the der encoded cert and negotiated protocol.
func (*Archive) FindRequest ¶
FindRequest searches for the given request in the archive. Returns ErrNotFound if the request could not be found.
Does not use the request body, but reads the request body to prevent WPR from issuing a Connection Reset error when handling large upload requests. (https://bugs.chromium.org/p/chromium/issues/detail?id=1215668)
TODO: conditional requests
func (*Archive) StartNewReplaySession ¶
func (a *Archive) StartNewReplaySession()
Start a new replay session so that the archive serves responses from the start. If an archive contains multiple identical requests with different responses, the archive can serve the responses in chronological order. This function resets the archive serving order to the start.
func (*Archive) Trim ¶
func (a *Archive) Trim(trimMatch func(req *http.Request, resp *http.Response) (bool, error)) (*Archive, error)
Trim iterates over all requests in the archive. For each request, it calls f to see if the request should be removed the archive. The trimmed archive is returned, leaving the current archive unchanged.
type ArchivedRequest ¶
type ArchivedRequest struct { SerializedRequest []byte SerializedResponse []byte // if empty, the request failed LastServedSessionId uint32 }
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 ¶
func (*Installer) AdbInstallRoot ¶
func (*Installer) AdbUninstallRoot ¶
func (*Installer) InstallRoot ¶
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 RequestMatch ¶
type RequestMatch struct { Match *ArchivedRequest Request *http.Request Response *http.Response MatchRatio float64 }
RequestMatch represents a match when querying the archive for responses to a request
func (*RequestMatch) SetMatch ¶
func (requestMatch *RequestMatch) SetMatch( match *ArchivedRequest, request *http.Request, response *http.Response, ratio float64)
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. // Inject these extra headers into the response ExtraHeaders http.Header // Inject these HTTP/2 PUSH_PROMISE frames into the response Push []PushPromiseRule // 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 ¶
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.