http

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IsPrivateIP = 1
	IsPublicIP  = 2
)

Variables

View Source
var ErrBatchForbiddenInInitContext = common.NewInitContextError("Using batch in the init context is not supported")

ErrBatchForbiddenInInitContext is used when batch was made in the init context

View Source
var ErrHTTPForbiddenInInitContext = common.NewInitContextError("Making http requests in the init context is not supported")

ErrHTTPForbiddenInInitContext is used when a http requests was made in the init context

View Source
var ErrJarForbiddenInInitContext = common.NewInitContextError("Making cookie jars in the init context is not supported")

ErrJarForbiddenInInitContext is used when a cookie jar was made in the init context TODO: unexport this? there's no reason for this to be exported

Functions

This section is empty.

Types

type Client

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

Client represents a stand-alone HTTP client.

TODO: move to its own file

func (*Client) Batch

func (c *Client) Batch(reqsV ...goja.Value) (interface{}, error)

Batch makes multiple simultaneous HTTP requests. The provideds reqsV should be an array of request objects. Batch returns an array of responses and/or error

func (*Client) Request

func (c *Client) Request(method string, url goja.Value, args ...goja.Value) (*Response, error)

Rate limits the number of requests per second to a certain domain

func (*Client) SetResponseCallback

func (c *Client) SetResponseCallback(val goja.Value)

SetResponseCallback sets the responseCallback to the value provided. Supported values are expectedStatuses object or a `null` which means that metrics shouldn't be tagged as failed and `http_req_failed` should not be emitted - the behaviour previous to this

type CookieJar

type CookieJar struct {

	// js is to make it not be accessible from inside goja/js, the json is
	// for when it is returned from setup().
	Jar *cookiejar.Jar `js:"-" json:"-"`
	// contains filtered or unexported fields
}

CookieJar is cookiejar.Jar wrapper to be used in js scripts

func (CookieJar) Clear

func (j CookieJar) Clear(url string) error

Clear all cookies for a particular URL

func (CookieJar) CookiesForURL

func (j CookieJar) CookiesForURL(url string) map[string][]string

CookiesForURL return the cookies for a given url as a map of key and values

func (CookieJar) Delete

func (j CookieJar) Delete(url, name string) error

Delete cookies for a particular URL

func (CookieJar) Set

func (j CookieJar) Set(url, name, value string, opts goja.Value) (bool, error)

Set sets a cookie for a particular url with the given name value and additional opts

type FileData

type FileData struct {
	Data        []byte
	Filename    string
	ContentType string
}

FileData represents a binary file requiring multipart request encoding

type ModuleInstance

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

ModuleInstance represents an instance of the HTTP module for every VU.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports returns the JS values this module exports.

func (*ModuleInstance) URL

func (mi *ModuleInstance) URL(parts []string, pieces ...string) (httpext.URL, error)

URL creates a new URL wrapper from the provided parts.

type Response

type Response struct {
	*httpext.Response `js:"-"`
	// contains filtered or unexported fields
}

Response is a representation of an HTTP response to be returned to the goja VM

func (res *Response) ClickLink(args ...goja.Value) (*Response, error)

ClickLink parses the body as an html, looks for a link and than makes a request as if the link was clicked

func (*Response) HTML

func (res *Response) HTML(selector ...string) html.Selection

HTML returns the body as an html.Selection

func (*Response) JSON

func (res *Response) JSON(selector ...string) goja.Value

JSON parses the body of a response as JSON and returns it to the goja VM.

func (*Response) SubmitForm

func (res *Response) SubmitForm(args ...goja.Value) (*Response, error)

SubmitForm parses the body as an html looking for a from and then submitting it TODO: document the actual arguments that can be provided

type RootModule

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

RootModule is the global module object type. It is instantiated once per test run and will be used to create HTTP module instances for each VU.

TODO: add sync.Once for all of the deprecation warnings we might want to do for the old k6/http APIs here, so they are shown only once in a test run.

func New

func New(workerInfo *libWorker.WorkerInfo) *RootModule

New returns a pointer to a new HTTP RootModule.

func (*RootModule) NewModuleInstance

func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance returns an HTTP module instance for each VU.

Jump to

Keyboard shortcuts

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