fhttp

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPReqTimeOutDefaultValue = 15 * time.Second
)

Version is the fortio package version (TODO:auto gen/extract).

View Source
const MaxDelay = 1 * time.Second

MaxDelay is the maximum delay allowed for the echoserver responses.

Variables

View Source
var (
	// BufferSizeKb size of the buffer (max data) for optimized client in kilobytes defaults to 32k.
	BufferSizeKb = 128
	// CheckConnectionClosedHeader indicates whether to check for server side connection closed headers.
	CheckConnectionClosedHeader = false
)
View Source
var (
	// EchoRequests is the number of request received. Only updated in Debug mode.
	EchoRequests int64
)

Functions

func ASCIIToUpper

func ASCIIToUpper(str string) []byte

ASCIIToUpper returns a byte array equal to the input string but in lowercase. Only wotks for ASCII, not meant for unicode.

func DebugHandler

func DebugHandler(w http.ResponseWriter, r *http.Request)

DebugHandler returns debug/useful info to http client.

func DebugSummary

func DebugSummary(buf []byte, max int) string

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

func DynamicHTTPServer(secure bool) (int, *http.ServeMux)

DynamicHTTPServer listens on an available port, sets up an http or https (when secure is true) server on it and returns the listening port and mux to which one can attach handlers to.

func EchoHandler

func EchoHandler(w http.ResponseWriter, r *http.Request)

EchoHandler is an http server handler echoing back the input.

func EscapeBytes

func EscapeBytes(buf []byte) string

EscapeBytes returns printable string. Same as %q format without the surrounding/extra "".

func FoldFind

func FoldFind(haystack []byte, needle []byte) (bool, int)

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 ParseChunkSize

func ParseChunkSize(inp []byte) (int, int)

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

func ParseDecimal(inp []byte) int

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 RoundDuration added in v0.3.7

func RoundDuration(d time.Duration) time.Duration

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

func Serve(port int, debugPath string)

Serve starts a debug / echo http server on the given port. TODO: make it work for port 0 and return the port found and also add a non blocking mode that makes sure the socket exists before returning

Types

type BasicClient

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

BasicClient is a fast, lockfree single purpose http 1.0/1.1 client.

func (*BasicClient) Fetch

func (c *BasicClient) Fetch() (int, []byte, int)

Fetch fetches the url content. Returns http code, data, offset of body.

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

func (c *Client) ChangeURL(urlStr string) (err error)

ChangeURL only for standard client, allows fetching a different URL

func (*Client) Fetch

func (c *Client) Fetch() (int, []byte, int)

Fetch fetches the byte and code for pre created client

type Fetcher

type Fetcher interface {
	// Fetch returns http code, data, offset of body (for client which returns
	// headers)
	Fetch() (int, []byte, int)
}

Fetcher is the Url content fetcher that the different client implements.

func NewBasicClient

func NewBasicClient(o *HTTPOptions) Fetcher

NewBasicClient 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.

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)

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

	HTTPReqTimeOut time.Duration // timeout value for http request
	// 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 main.go for example).

func (*HTTPOptions) GetHeaders added in v0.4.2

func (h *HTTPOptions) GetHeaders() http.Header

GetHeaders returns the current set of 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). It replaces plain % to %25 in the url. If you already have properly escaped URLs use o.URL = to set it.

func (*HTTPOptions) ResetHeaders added in v0.4.2

func (h *HTTPOptions) ResetHeaders()

ResetHeaders resets all the headers, including the User-Agent one.

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.

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
}

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
	// 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.

Jump to

Keyboard shortcuts

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