response

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package response executes HTTP requests and handles the response.

Index

Constants

View Source
const (
	// DefaultMaxBodySize is the default size for peeking at the body to extract strings via regexp.
	DefaultMaxBodySize = 5 * 1024 * 1024

	// DefaultConnectTimeout limits how long the TCP connection setup can take.
	DefaultConnectTimeout = 30 * time.Second

	// DefaultTLSHandshakeTimeout limits the time until a TLS connection must be established.
	DefaultTLSHandshakeTimeout = 10 * time.Second

	// DefaultResponseHeaderTimeout limits the time until the first HTTP
	// response header must have been received.
	DefaultResponseHeaderTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func AddTransportFlags added in v0.8.0

func AddTransportFlags(fs *pflag.FlagSet, opts *TransportOptions)

func Mark

func Mark(in <-chan Response, filters []Filter) <-chan Response

Mark runs all responses through filters and sets the Hide attribute if a filter matches. Filtering is done in a separate goroutine, which terminates when the input channel is closed.

func NewTransport

func NewTransport(opts TransportOptions, concurrentRequests int) (*http.Transport, error)

NewTransport creates a new shared transport for clients to use.

Types

type Extracter

type Extracter struct {
	Pattern  []*regexp.Regexp
	Commands [][]string
}

Extracter collects data from interesting (non-hidden) responses.

func (*Extracter) Run

func (e *Extracter) Run(ctx context.Context, numWorkers int, in <-chan Response) <-chan Response

Run extracts data from the body of a response by running external commands and feeding them the response body. Commands used to extract data are only run for non-hidden responses, since this is expensive.

The values that were used to produce the request are passed in the environment variable $MONSOON_VALUE (for the first one) and $MONSOON_VALUE1 to $MONSOON_VALUEN if several values were used.

type Filter

type Filter interface {
	Reject(Response) bool
}

Filter decides whether to reject a Response.

type FilterAcceptPattern

type FilterAcceptPattern struct {
	Pattern []*regexp.Regexp
}

FilterAcceptPattern filters responses based on patterns (header and body are matched).

func (FilterAcceptPattern) Reject

func (f FilterAcceptPattern) Reject(res Response) bool

Reject decides if r is to be printed.

type FilterRejectPattern

type FilterRejectPattern struct {
	Pattern []*regexp.Regexp
}

FilterRejectPattern filters responses based on patterns (header and body are matched).

func (FilterRejectPattern) Reject

func (f FilterRejectPattern) Reject(res Response) bool

Reject decides if r is to be printed.

type FilterSize

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

FilterSize hides responses based on a size.

func NewFilterSize

func NewFilterSize(headerBytes, bodyBytes []string) (FilterSize, error)

NewFilterSize returns an initialized FilterSize.

func (FilterSize) Reject

func (f FilterSize) Reject(r Response) bool

Reject decides if r is to be printed.

type FilterStatusCode

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

FilterStatusCode hides responses based on the HTTP status code.

func NewFilterStatusCode

func NewFilterStatusCode(rejects, accepts []string) (FilterStatusCode, error)

NewFilterStatusCode returns a filter based on HTTP status code.

func (FilterStatusCode) Reject

func (f FilterStatusCode) Reject(r Response) bool

Reject decides if r is to be printed.

type InvalidRequest added in v0.7.0

type InvalidRequest struct {
	Err error
}

func (InvalidRequest) Error added in v0.7.0

func (ir InvalidRequest) Error() string

type Response

type Response struct {
	Values   []string
	URL      string
	Error    error
	Duration time.Duration

	Header, BodyStats TextStats
	Extract           []string
	ExtractError      error

	HTTPResponse *http.Response
	Body         []byte
	RawHeader    []byte
	Decompressed bool

	Hide bool // can be set by a filter, response should not be displayed
}

Response is an HTTP response.

func (*Response) ExtractBody

func (r *Response) ExtractBody(targets []*regexp.Regexp)

ExtractBody extracts data from the HTTP response body.

func (*Response) ExtractBodyCommand

func (r *Response) ExtractBodyCommand(ctx context.Context, cmds [][]string) (err error)

ExtractBodyCommand extracts data from the HTTP response body by running an external command.

func (*Response) ExtractHeader

func (r *Response) ExtractHeader(res *http.Response, targets []*regexp.Regexp) error

ExtractHeader extracts data from an HTTP header. This fills r.Header.

func (*Response) ReadBody

func (r *Response) ReadBody(res *http.Response, maxBodySize int, decompress bool) (finalError error)

ReadBody reads at most maxBodySize bytes from the body and saves it to a buffer in the Response struct for later processing.

func (Response) String

func (r Response) String() string

type Runner

type Runner struct {
	Template *request.Request

	MaxBodySize int
	Extract     []*regexp.Regexp

	Client                 *http.Client
	Transport              *http.Transport
	DecompressResponseBody bool

	PreserveRequestBody bool
	// contains filtered or unexported fields
}

Runner executes HTTP requests.

func NewRunner

func NewRunner(tr *http.Transport, template *request.Request, input <-chan []string, output chan<- Response) *Runner

NewRunner returns a new runner to execute HTTP requests.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context)

Run processes items read from ch and executes HTTP requests.

type TextStats

type TextStats struct {
	Bytes int `json:"bytes"`
	Words int `json:"words"`
	Lines int `json:"lines"`
}

TextStats reports statistics about some text.

func Count

func Count(rd io.Reader) (TextStats, error)

Count counts the bytes, words and lines in the body.

type TransportOptions added in v0.8.0

type TransportOptions struct {
	SkipCertificateVerification         bool
	EnableInsecureCiphersAndTLSVersions bool
	TLSClientCertKeyFilename            string
	DisableHTTP2                        bool
	Network                             string

	ConnectTimeout        time.Duration
	TLSHandshakeTimeout   time.Duration
	ResponseHeaderTimeout time.Duration
}

func (TransportOptions) Valid added in v0.8.0

func (t TransportOptions) Valid() error

Jump to

Keyboard shortcuts

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