fhttp

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2017 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

DynamicHTTPServer listens on an available port, sets up an http or https (when secure is true) server on it and returns the listening port.

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 FetchURL

func FetchURL(url string) (int, []byte, int)

FetchURL fetches URL content and does error handling/logging. Version not reusing the client.

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.

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 (*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)

func NewStdClient

func NewStdClient(o *HTTPOptions) Fetcher

NewStdClient creates a client object that wraps the net/http standard client.

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

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

func (*HTTPOptions) ResetHeaders added in v0.4.2

func (h *HTTPOptions) ResetHeaders()

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

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
}

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