http

package
v0.0.0-...-6503209 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckStep

func CheckStep(ctx context.Context, b *Browser, step *Step, debug *log.Logger) error

Types

type BasicAuth

type BasicAuth struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type Browser

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

Browser pretends (badly) to emulate a browser, to the extent that it keeps cookies across requests. It maintains state with the last browsed page, so that one can find elements in it using jquery-like CSS selector syntax, and click links or submit forms.

func NewBrowser

func NewBrowser(tlsConfig *tls.Config, debug *log.Logger, dnsMap map[string]string) *Browser

NewBrowser creates a new Browser with the given tls configuration. Its debugging output will be sent to the specified Logger.

func (*Browser) Click

func (b *Browser) Click(ctx context.Context, linkSelector string) (*Response, error)

Click on a link, identified by a CSS selector. The resulting element should have an 'href' attribute, and we'll navigate to that.

func (*Browser) Dump

func (b *Browser) Dump(l *log.Logger)

func (*Browser) Open

func (b *Browser) Open(ctx context.Context, method, uri string, opts *RequestOptions) (*Response, error)

Open a new page, discarding the current state.

func (*Browser) SubmitForm

func (b *Browser) SubmitForm(ctx context.Context, formSelector string, moreValues map[string]string) (*Response, error)

SubmitForm finds the specified form using a CSS selector, retrieves default values and modifies them with moreValues, and submits the form.

type RequestOptions

type RequestOptions struct {
	Args    url.Values
	Headers map[string]string
}

type Response

type Response struct {
	URL        *url.URL
	StatusCode int
	Header     http.Header
	Body       string
	Doc        *goquery.Document
}

Response is an abridged version of the http.Response.

type Step

type Step struct {
	Name       string            `json:"name"`
	Type       string            `json:"type"`
	URL        string            `json:"url"`
	Method     string            `json:"method"`
	Headers    map[string]string `json:"headers"`
	FormValues map[string]string `json:"form_values"`
	BasicAuth  *BasicAuth        `json:"basic_auth"`

	Selector string `json:"selector"`

	ExpectedURL  jsontypes.Regexp `json:"expected_url"`
	ExpectedData jsontypes.Regexp `json:"expected_data"`
}

A Step in a script, a series of HTTP transactions whose results we can verify somehow (right now just by needle-in-haystack string matching).

Jump to

Keyboard shortcuts

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