proxy

package
v0.0.0-...-295d36a Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPrivateKey

func LoadPrivateKey(derPath string) (*ecdsa.PrivateKey, error)

func PrivateKey

func PrivateKey() (*ecdsa.PrivateKey, error)

PrivateKey generates a new key.

func SavePrivateKey

func SavePrivateKey(pk *ecdsa.PrivateKey, derPath string) error

Types

type Action

type Action string
const (
	// Do not allow the request under any circumstances
	Reject Action = "REJECT"
	// Only allow requests that have a captured response
	Locked Action = "LOCKED"
	// Allow requests matching the pattern, preferring cached responses
	Allow Action = "ALLOW"
	// Always refresh, even when in cache
	Refresh Action = "REFRESH"
	// Always allow the request, and never cache the response. This should only be used for authentication tokens.
	RefreshNoStore Action = "NO_STORE"
)

func ParseAction

func ParseAction(s string) Action

func (Action) String

func (a Action) String() string

type CertIssuer

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

func NewCertIssuer

func NewCertIssuer(pk *ecdsa.PrivateKey) (*CertIssuer, error)

func (*CertIssuer) CertPEM

func (i *CertIssuer) CertPEM() []byte

func (*CertIssuer) Issue

func (i *CertIssuer) Issue(cn string) (*tls.Certificate, error)

type Config

type Config struct {
	Rules []*Rule
}

func LoadConfig

func LoadConfig(in io.Reader) (*Config, error)

func LoadConfigFile

func LoadConfigFile(fn string) (*Config, error)

func (*Config) Save

func (c *Config) Save(fn string) error

type FileStorage

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

func NewFileStorage

func NewFileStorage(log logr.Logger, blobDir string) (*FileStorage, error)

func (*FileStorage) Load

func (s *FileStorage) Load(data *URLData) ([]byte, error)

func (*FileStorage) Store

func (s *FileStorage) Store(data *URLData, content []byte) error

type Filter

type Filter struct {
	Rules []*Rule
	// contains filtered or unexported fields
}

func NewFilter

func NewFilter(log logr.Logger, handler http.Handler, rules ...*Rule) *Filter

func (*Filter) ServeHTTP

func (f *Filter) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LRUStorage

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

func NewLRUStorage

func NewLRUStorage(size int, source Storage) (*LRUStorage, error)

func (*LRUStorage) Load

func (s *LRUStorage) Load(d *URLData) ([]byte, error)

func (*LRUStorage) Store

func (s *LRUStorage) Store(data *URLData, content []byte) error

type Proxy

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

Proxy acts as an HTTP proxy, and TLS interceptor. HTTP CONNECT requests, as a client would issue for an HTTPS server, are intercepted by a self-signed CA.

func NewProxy

func NewProxy(handler http.Handler, opts ...ProxyOpt) (*Proxy, error)

func (*Proxy) Close

func (p *Proxy) Close() error

func (*Proxy) IssuerCertPEM

func (p *Proxy) IssuerCertPEM() []byte

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Proxy) URL

func (p *Proxy) URL() *url.URL

type ProxyOpt

type ProxyOpt func(*Proxy)

func ProxyWithLog

func ProxyWithLog(log logr.Logger) ProxyOpt

func ProxyWithPrivateKey

func ProxyWithPrivateKey(pk *ecdsa.PrivateKey) ProxyOpt

func ProxyWithSocketPath

func ProxyWithSocketPath(socketPath string) ProxyOpt

type RedisStorage

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

func NewRedisStorage

func NewRedisStorage(redis *redis.Client, prefix string) *RedisStorage

func (*RedisStorage) Load

func (s *RedisStorage) Load(data *URLData) ([]byte, error)

func (*RedisStorage) Store

func (s *RedisStorage) Store(data *URLData, content []byte) error

type Rule

type Rule struct {
	Action Action
	// contains filtered or unexported fields
}

func NewRule

func NewRule(pattern string, action Action) (*Rule, error)

func (*Rule) MatchString

func (r *Rule) MatchString(url string) bool

type Snapshot

type Snapshot struct {
	Data map[string]*URLData `yaml:"data"`
	// contains filtered or unexported fields
}

func LoadSnapshot

func LoadSnapshot(index string) (*Snapshot, error)

func NewSnapshot

func NewSnapshot() *Snapshot

func (*Snapshot) ByHost

func (s *Snapshot) ByHost() map[string]map[string]*URLData

func (*Snapshot) Clear

func (s *Snapshot) Clear()

func (*Snapshot) Empty

func (s *Snapshot) Empty() bool

func (*Snapshot) Get

func (s *Snapshot) Get(key string) *URLData

func (*Snapshot) Save

func (s *Snapshot) Save(fn string) error

Save writes this snapshot to a unique filename within the given directory

func (*Snapshot) Set

func (s *Snapshot) Set(key string, data *URLData)

func (*Snapshot) Size

func (s *Snapshot) Size() int

type Snapshotter

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

func NewSnapshotter

func NewSnapshotter(log logr.Logger, snap *Snapshot, storage Storage) *Snapshotter

func (*Snapshotter) ServeHTTP

func (s *Snapshotter) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Storage

type Storage interface {
	Load(*URLData) ([]byte, error)
	Store(data *URLData, content []byte) error
}

type URLData

type URLData struct {
	StatusCode    int    `yaml:"responseCode,omitempty"`
	ContentType   string `yaml:"contentType,omitempty"`
	ContentLength int    `yaml:"contentLength,omitempty"`
	Sha256        string `yaml:"sha256"`
	Shake256      string `yaml:"shake256"`
}

func NewURLData

func NewURLData(r *httptest.ResponseRecorder) *URLData

Jump to

Keyboard shortcuts

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