Documentation ¶
Index ¶
- Constants
- Variables
- func ASCIIToUpper(str string) []byte
- func AddHTTPS(url string) string
- func CacheOn(w http.ResponseWriter)
- func DebugHandler(w http.ResponseWriter, r *http.Request)
- func DebugSummary(buf []byte, max int) string
- func DynamicHTTPServer(closing bool) (*http.ServeMux, *net.TCPAddr)
- func EchoHandler(w http.ResponseWriter, r *http.Request)
- func EscapeBytes(buf []byte) string
- func Fetch(httpOptions *HTTPOptions) (int, []byte)
- func FetchURL(url string) (int, []byte)
- func FetcherHandler(w http.ResponseWriter, r *http.Request)
- func FoldFind(haystack []byte, needle []byte) (bool, int)
- func HTTPServer(name string, port string) (*http.ServeMux, net.Addr)
- func LogAndCall(msg string, hf http.HandlerFunc) http.HandlerFunc
- func LogAndCallNoArg(msg string, f func()) http.HandlerFunc
- func LogRequest(r *http.Request, msg string)
- func NewHTMLEscapeWriter(w io.Writer) io.Writer
- func OnBehalfOf(o *HTTPOptions, r *http.Request)
- func ParseChunkSize(inp []byte) (int, int)
- func ParseDecimal(inp []byte) int
- func RedirectToHTTPS(port string) net.Addr
- func RedirectToHTTPSHandler(w http.ResponseWriter, r *http.Request)
- func RoundDuration(d time.Duration) time.Duration
- func Serve(port, debugPath string) (*http.ServeMux, net.Addr)
- func ServeTCP(port, debugPath string) (*http.ServeMux, *net.TCPAddr)
- func SetupPPROF(mux *http.ServeMux)
- type Client
- type FastClient
- type Fetcher
- type HTMLEscapeWriter
- type HTTPOptions
- func (h *HTTPOptions) AddAndValidateExtraHeader(hdr string) error
- func (h *HTTPOptions) AllHeaders() http.Header
- func (h *HTTPOptions) GenerateHeaders() http.Header
- func (h *HTTPOptions) Init(url string) *HTTPOptions
- func (h *HTTPOptions) InitHeaders()
- func (h *HTTPOptions) Method() string
- func (h *HTTPOptions) PayloadString() string
- func (h *HTTPOptions) ResetHeaders()
- func (h *HTTPOptions) URLSchemeCheck()
- func (h *HTTPOptions) ValidateAndAddBasicAuthentication(headers http.Header) error
- type HTTPRunnerOptions
- type HTTPRunnerResults
Constants ¶
const ( // SocketError is return when a transport error occurred: unexpected EOF, connection error, etc... SocketError = -1 // RetryOnce is used internally as an error code to allow 1 retry for bad socket reuse. RetryOnce = -2 )
Extra error codes outside of the HTTP Status code ranges. ie negative.
const ( // HTTPReqTimeOutDefaultValue is the default timeout value. 15s. HTTPReqTimeOutDefaultValue = 15 * time.Second )
const MaxDelay = 1500 * time.Millisecond
MaxDelay is the maximum delay allowed for the echoserver responses. 1.5s so we can test the default 1s timeout in envoy.
Variables ¶
var ( // BufferSizeKb size of the buffer (max data) for optimized client in kilobytes defaults to 128k. BufferSizeKb = 128 // CheckConnectionClosedHeader indicates whether to check for server side connection closed headers. CheckConnectionClosedHeader = false )
var ( // EchoRequests is the number of request received. Only updated in Debug mode. EchoRequests int64 )
Functions ¶
func ASCIIToUpper ¶
ASCIIToUpper returns a byte array equal to the input string but in lowercase. Only works for ASCII, not meant for unicode.
func AddHTTPS ¶ added in v1.0.0
AddHTTPS replaces "http://" in url with "https://" or prepends "https://" if url does not contain prefix "http://".
func CacheOn ¶ added in v0.9.0
func CacheOn(w http.ResponseWriter)
CacheOn sets the header for indefinite caching.
func DebugHandler ¶
func DebugHandler(w http.ResponseWriter, r *http.Request)
DebugHandler returns debug/useful info to http client.
func DebugSummary ¶
DebugSummary returns a string with the size and escaped first max/2 and last max/2 bytes of a buffer (or the whole escaped buffer if small enough).
func DynamicHTTPServer ¶
DynamicHTTPServer listens on an available port, sets up an http or a closing server simulating an https server (when closing is true) server on it and returns the listening port and mux to which one can attach handlers to. Note: in a future version of istio, the closing will be actually be secure on/off and create an https server instead of a closing server. As this is a dynamic tcp socket server, the address is TCP.
func EchoHandler ¶
func EchoHandler(w http.ResponseWriter, r *http.Request)
EchoHandler is an http server handler echoing back the input.
func EscapeBytes ¶
EscapeBytes returns printable string. Same as %q format without the surrounding/extra "".
func Fetch ¶ added in v0.8.0
func Fetch(httpOptions *HTTPOptions) (int, []byte)
Fetch creates a client an performs a fetch according to the http options passed in. To be used only for single fetches or when performance doesn't matter as the client is closed at the end.
func FetchURL ¶
FetchURL fetches the data at the given url using the standard client and default options. Returns the http status code (http.StatusOK == 200 for success) and the data. To be used only for single fetches or when performance doesn't matter as the client is closed at the end.
func FetcherHandler ¶ added in v0.8.0
func FetcherHandler(w http.ResponseWriter, r *http.Request)
FetcherHandler is the handler for the fetcher/proxy.
func FoldFind ¶
FoldFind searches the bytes assuming ascii, ignoring the lowercase bit for testing. Not intended to work with unicode, meant for http headers and to be fast (see benchmark in test file).
func HTTPServer ¶ added in v0.8.0
HTTPServer creates an http server named name on address/port port. Port can include binding address and/or be port 0.
func LogAndCall ¶ added in v0.8.0
func LogAndCall(msg string, hf http.HandlerFunc) http.HandlerFunc
LogAndCall wrapps an HTTP handler to log the request first.
func LogAndCallNoArg ¶ added in v1.4.2
func LogAndCallNoArg(msg string, f func()) http.HandlerFunc
LogAndCallNoArg is LogAndCall for functions not needing the response/request args
func LogRequest ¶ added in v0.8.0
LogRequest logs the incoming request, including headers when loglevel is verbose
func NewHTMLEscapeWriter ¶ added in v0.8.0
NewHTMLEscapeWriter creates a io.Writer that can safely output to an http.ResponseWrite with HTMLEscape-ing.
func OnBehalfOf ¶ added in v0.8.0
func OnBehalfOf(o *HTTPOptions, r *http.Request)
OnBehalfOf adds a header with the remote addr to an http options object.
func ParseChunkSize ¶
ParseChunkSize extracts the chunk size and consumes the line. Returns the offset of the data and the size of the chunk, 0, -1 when not found.
func ParseDecimal ¶
ParseDecimal extracts the first positive integer number from the input. spaces are ignored. any character that isn't a digit cause the parsing to stop
func RedirectToHTTPS ¶ added in v0.8.0
RedirectToHTTPS Sets up a redirector to https on the given port. (Do not create a loop, make sure this is addressed from an ingress)
func RedirectToHTTPSHandler ¶ added in v0.8.0
func RedirectToHTTPSHandler(w http.ResponseWriter, r *http.Request)
RedirectToHTTPSHandler handler sends a redirect to same URL with https.
func RoundDuration ¶ added in v0.3.7
RoundDuration rounds to 10th of second. Only for positive durations. TODO: switch to Duration.Round once switched to go 1.9
func Serve ¶ added in v0.3.7
Serve starts a debug / echo http server on the given port. Returns the mux and addr where the listening socket is bound. The .Port can be retrieved from it when requesting the 0 port as input for dynamic http server.
func ServeTCP ¶ added in v1.1.0
ServeTCP is Serve() but restricted to TCP (return address is assumed to be TCP - will panic for unix domain)
func SetupPPROF ¶ added in v0.8.0
SetupPPROF add pprof to the mux (mirror the init() of http pprof).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client object for making repeated requests of the same URL using the same http client (net/http)
func NewStdClient ¶
func NewStdClient(o *HTTPOptions) *Client
NewStdClient creates a client object that wraps the net/http standard client.
func (*Client) ChangeURL ¶ added in v0.6.4
ChangeURL only for standard client, allows fetching a different URL
type FastClient ¶ added in v0.7.2
type FastClient struct {
// contains filtered or unexported fields
}
FastClient is a fast, lockfree single purpose http 1.0/1.1 client.
func (*FastClient) Close ¶ added in v0.7.2
func (c *FastClient) Close() int
Close cleans up any resources used by FastClient
type Fetcher ¶
type Fetcher interface { // Fetch returns http code, data, offset of body (for client which returns // headers) Fetch() (int, []byte, int) // Close() cleans up connections and state - must be paired with NewClient calls. // returns how many sockets have been used (Fastclient only) Close() int }
Fetcher is the Url content fetcher that the different client implements.
func NewClient ¶ added in v0.4.2
func NewClient(o *HTTPOptions) Fetcher
NewClient creates either a standard or fast client (depending on the DisableFastClient flag)
func NewFastClient ¶ added in v0.7.2
func NewFastClient(o *HTTPOptions) Fetcher
NewFastClient makes a basic, efficient http 1.0/1.1 client. This function itself doesn't need to be super efficient as it is created at the beginning and then reused many times.
type HTMLEscapeWriter ¶ added in v0.8.0
HTMLEscapeWriter is an io.Writer escaping the output for safe html inclusion.
type HTTPOptions ¶ added in v0.4.2
type HTTPOptions struct { URL string NumConnections int // num connections (for std client) Compression bool // defaults to no compression, only used by std client DisableFastClient bool // defaults to fast client HTTP10 bool // defaults to http1.1 DisableKeepAlive bool // so default is keep alive AllowHalfClose bool // if not keepalive, whether to half close after request Insecure bool // do not verify certs for https FollowRedirects bool // For the Std Client only: follow redirects. Resolve string // resolve Common Name to this ip when use CN as target url HTTPReqTimeOut time.Duration // timeout value for http request UserCredentials string // user credentials for authorization ContentType string // indicates request body type, implies POST instead of GET Payload []byte // body for http request, implies POST if not empty. UnixDomainSocket string // Path of unix domain socket to use instead of host:port from URL // contains filtered or unexported fields }
HTTPOptions holds the common options of both http clients and the headers.
func NewHTTPOptions ¶ added in v0.4.2
func NewHTTPOptions(url string) *HTTPOptions
NewHTTPOptions creates and initialize a HTTPOptions object. It replaces plain % to %25 in the url. If you already have properly escaped URLs use o.URL = to set it.
func (*HTTPOptions) AddAndValidateExtraHeader ¶ added in v0.4.2
func (h *HTTPOptions) AddAndValidateExtraHeader(hdr string) error
AddAndValidateExtraHeader collects extra headers (see commonflags.go for example).
func (*HTTPOptions) AllHeaders ¶ added in v1.1.0
func (h *HTTPOptions) AllHeaders() http.Header
AllHeaders returns the current set of headers including virtual/special Host header.
func (*HTTPOptions) GenerateHeaders ¶ added in v1.1.0
func (h *HTTPOptions) GenerateHeaders() http.Header
GenerateHeaders completes the header generation, including Content-Type/Length and user credential coming from the http options in addition to extra headers coming from flags and AddAndValidateExtraHeader(). Warning this gets called more than once, do not generate duplicate headers.
func (*HTTPOptions) Init ¶ added in v0.4.2
func (h *HTTPOptions) Init(url string) *HTTPOptions
Init initializes the headers in an HTTPOptions (User-Agent).
func (*HTTPOptions) InitHeaders ¶ added in v0.7.3
func (h *HTTPOptions) InitHeaders()
InitHeaders initialize and/or resets the default headers (ie just User-Agent).
func (*HTTPOptions) Method ¶ added in v1.1.0
func (h *HTTPOptions) Method() string
Method returns the method of the http req.
func (*HTTPOptions) PayloadString ¶ added in v1.1.0
func (h *HTTPOptions) PayloadString() string
PayloadString returns the payload as a string. If payload is null return empty string This is only needed due to grpc ping proto. It takes string instead of byte array.
func (*HTTPOptions) ResetHeaders ¶ added in v0.4.2
func (h *HTTPOptions) ResetHeaders()
ResetHeaders resets all the headers, including the User-Agent: one (and the Host: logical special header). This is used from the UI as the user agent is settable from the form UI.
func (*HTTPOptions) URLSchemeCheck ¶ added in v0.6.7
func (h *HTTPOptions) URLSchemeCheck()
URLSchemeCheck makes sure the client will work with the scheme requested. it also adds missing http:// to emulate curl's behavior.
func (*HTTPOptions) ValidateAndAddBasicAuthentication ¶ added in v1.0.1
func (h *HTTPOptions) ValidateAndAddBasicAuthentication(headers http.Header) error
ValidateAndAddBasicAuthentication validates user credentials and adds basic authentication to http header, if user credentials are valid.
type HTTPRunnerOptions ¶
type HTTPRunnerOptions struct { periodic.RunnerOptions HTTPOptions // Need to call Init() to initialize Profiler string // file to save profiles to. defaults to no profiling AllowInitialErrors bool // whether initial errors don't cause an abort // Which status code cause an abort of the run (default 0 = don't abort; reminder -1 is returned for socket errors) AbortOn int }
HTTPRunnerOptions includes the base RunnerOptions plus http specific options.
type HTTPRunnerResults ¶
type HTTPRunnerResults struct { periodic.RunnerResults RetCodes map[int]int64 // exported result Sizes *stats.HistogramData HeaderSizes *stats.HistogramData URL string SocketCount int // http code to abort the run on (-1 for connection or other socket error) AbortOn int // contains filtered or unexported fields }
HTTPRunnerResults is the aggregated result of an HTTPRunner. Also is the internal type used per thread/goroutine.
func RunHTTPTest ¶
func RunHTTPTest(o *HTTPRunnerOptions) (*HTTPRunnerResults, error)
RunHTTPTest runs an http test and returns the aggregated stats.
func (*HTTPRunnerResults) Run ¶ added in v0.4.2
func (httpstate *HTTPRunnerResults) Run(t int)
Run tests http request fetching. Main call being run at the target QPS. To be set as the Function in RunnerOptions.