server

package
v0.0.0-...-86e0ce2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2017 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApacheFormatPattern = "%s - - [%s] %s \"%s %d %d\" %f\n"
)
View Source
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"

Variables

This section is empty.

Functions

func Address

func Address(addr string) func(*Server)

func Config

func Config(val string) func(*Server)

func HostNotConfigured

func HostNotConfigured(req *http.Request) (*http.Response, error)

func IsMediaType

func IsMediaType(contentType string, val string) bool

func NewApacheLoggingHandler

func NewApacheLoggingHandler(handler http.Handler, printFunc printFn) http.Handler

func NewChangeStream

func NewChangeStream(r io.ReadCloser) io.ReadCloser

func TLSAddress

func TLSAddress(addr string) func(*Server)

Types

type Action

type Action struct {
	Path        string   `toml:"path"`
	Method      []string `toml:"method"`
	RemoteAddr  []string `toml:"remote_addr"`
	Location    string   `toml:"location"`
	Action      string   `toml:"action"`
	StatusCode  int      `toml:"statuscode"`
	ContentType string   `toml:"content_type"`
	Body        string   `toml:"body"`
	UserAgent   []string `toml:"user_agent"`
	Scripts     []string `toml:"scripts"`

	Regex   string `toml:"regex"`
	Replace string `toml:"replace"`
	File    string `toml:"file"`
}

type ActionRequestFile

type ActionRequestFile struct {
	*Action
}

func (*ActionRequestFile) OnRequest

func (a *ActionRequestFile) OnRequest(req *http.Request) (*http.Request, *http.Response, error)

type ActionRequestRedirect

type ActionRequestRedirect struct {
	*Action
}

func (*ActionRequestRedirect) OnRequest

func (a *ActionRequestRedirect) OnRequest(req *http.Request) (*http.Request, *http.Response, error)

type ActionRequestServe

type ActionRequestServe struct {
	*Action
}

func (*ActionRequestServe) OnRequest

func (a *ActionRequestServe) OnRequest(req *http.Request) (*http.Request, *http.Response, error)

type ActionRequester

type ActionRequester interface {
	OnRequest(*http.Request) (*http.Request, *http.Response, error)
}

type ActionResponseInject

type ActionResponseInject struct {
	*Action
}

func (*ActionResponseInject) OnResponse

func (a *ActionResponseInject) OnResponse(req *http.Request, resp *http.Response) (*http.Response, error)

type ActionResponseReplace

type ActionResponseReplace struct {
	*Action
}

func (*ActionResponseReplace) OnResponse

func (a *ActionResponseReplace) OnResponse(req *http.Request, resp *http.Response) (*http.Response, error)

type ActionResponserer

type ActionResponserer interface {
	OnResponse(*http.Request, *http.Response) (*http.Response, error)
}

type ApacheLogRecord

type ApacheLogRecord struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*ApacheLogRecord) Log

func (r *ApacheLogRecord) Log(printFunc printFn)

func (*ApacheLogRecord) Write

func (r *ApacheLogRecord) Write(p []byte) (int, error)

func (*ApacheLogRecord) WriteHeader

func (r *ApacheLogRecord) WriteHeader(status int)

type ApacheLoggingHandler

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

func (*ApacheLoggingHandler) ServeHTTP

func (h *ApacheLoggingHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type ChangeStream

type ChangeStream struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

func (*ChangeStream) Close

func (cs *ChangeStream) Close() error

func (*ChangeStream) Read

func (cs *ChangeStream) Read(p []byte) (n int, err error)
type Cookie struct {
	Name  string
	Value string

	Path       string    // optional
	Domain     string    // optional
	Expires    time.Time // optional
	RawExpires string    // for reading cookies only

	// MaxAge=0 means no 'Max-Age' attribute specified.
	// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
	// MaxAge>0 means Max-Age attribute present and given in seconds
	MaxAge   int
	Secure   bool
	HttpOnly bool
	Raw      string
	Unparsed []string // Raw text of unparsed attribute-value pairs
}

A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an HTTP response or the Cookie header of an HTTP request.

See http://tools.ietf.org/html/rfc6265 for details.

func (*Cookie) String

func (c *Cookie) String() string

String returns the serialization of the cookie for use in a Cookie header (if only Name and Value are set) or a Set-Cookie response header (if other fields are set). If c is nil or c.Name is invalid, the empty string is returned.

type Document

type Document struct {
	Date       time.Time              `json:"date"`
	RemoteAddr string                 `json:"remote_addr"`
	Meta       map[string]interface{} `json:"meta,omitempty"`
	Request    *Request               `json:"request"`
	Response   *Response              `json:"response,omitempty"`
}

type Host

type Host struct {
	Host    string   `toml:"host"`
	Target  string   `toml:"target"`
	Actions []Action `toml:"action"`
}

type Request

type Request struct {
	Method        string              `json:"method,omitempty"`
	URL           string              `json:"url,omitempty"`
	Proto         string              `json:"proto,omitempty"`
	Host          string              `json:"host,omitempty"`
	Cookies       map[string]string   `json:"cookies,omitempty"`
	ContentLength int64               `json:"content_length,omitempty"`
	Header        map[string][]string `json:"headers,omitempty"`
	Body          string              `json:"body,omitempty"`
}

type Response

type Response struct {
	StatusCode    int                 `json:"status_code,omitempty"`
	ContentLength int64               `json:"content_length,omitempty"`
	Proto         string              `json:"proto,omitempty"`
	Header        map[string][]string `json:"headers,omitempty"`
	Body          string              `json:"body,omitempty"`
	Hash          struct {
		SHA256 string `json:"sha256,omitempty"`
	} `json:"hashes,omitempty"`
}

type Server

type Server struct {
	Cache *cache.Cache

	// Director must be a function which modifies
	// the request into a new request to be sent
	// using Transport. Its response is then copied
	// back to the original client unmodified.
	Director func(*http.Request)

	// The transport used to perform proxy requests.
	// If nil, http.DefaultTransport is used.
	http.RoundTripper

	// FlushInterval specifies the flush interval
	// to flush to the client while copying the
	// response body.
	// If zero, no periodic flushing is done.
	FlushInterval time.Duration
	// contains filtered or unexported fields
}

func New

func New(options ...func(*Server)) *Server

func (*Server) GetHost

func (p *Server) GetHost(hst string) *Host

func (*Server) RoundTrip

func (t *Server) RoundTrip(req *http.Request) (resp *http.Response, err error)

func (*Server) Run

func (c *Server) Run()

func (*Server) ServeHTTP

func (p *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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