response

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package response executes HTTP requests and handles the response.

Index

Constants

View Source
const DefaultMaxBodySize = 5 * 1024 * 1024

DefaultMaxBodySize is the default size for peeking at the body to extract strings via regexp.

Variables

This section is empty.

Functions

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(insecure bool, TLSClientCertKeyFilename string,
	disableHTTP2 bool, 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
	Error    func(error)
}

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

func (*Extracter) Run

func (e *Extracter) Run(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. Extraction is done in a separate goroutine, which terminates when the input channel is closed.

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 Response

type Response struct {
	Item     string
	URL      string
	Error    error
	Duration time.Duration

	Header, Body TextStats
	Extract      []string

	HTTPResponse *http.Response
	RawBody      []byte
	RawHeader    []byte

	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(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(body io.Reader, maxBodySize int) (err 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
	// 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) (stats TextStats, err error)

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

Jump to

Keyboard shortcuts

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