http

package
v0.43.1 Latest Latest
Warning

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

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

Documentation

Overview

Package http implements the k6/http js module for k6. That module is used to make http requests.

Index

Constants

This section is empty.

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 added in v0.36.0

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

Client represents a stand-alone HTTP client.

TODO: move to its own file

func (*Client) Batch added in v0.36.0

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 added in v0.36.0

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

Request makes an http request of the provided `method` and returns a corresponding response by taking goja.Values as arguments

func (*Client) SetResponseCallback added in v0.36.0

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 added in v0.36.0

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 added in v0.39.0

func (j CookieJar) Clear(url string) error

Clear all cookies for a particular URL

func (CookieJar) CookiesForURL added in v0.36.0

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 added in v0.39.0

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

Delete cookies for a particular URL

func (CookieJar) Set added in v0.36.0

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 added in v0.20.0

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

FileData represents a binary file requiring multipart request encoding

type ModuleInstance added in v0.36.0

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

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

func (*ModuleInstance) Exports added in v0.36.0

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

Exports returns the JS values this module exports.

func (*ModuleInstance) URL added in v0.36.0

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

URL creates a new URL wrapper from the provided parts.

type Response added in v0.24.0

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 added in v0.24.0

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

HTML returns the body as an html.Selection

func (*Response) JSON added in v0.24.0

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 added in v0.24.0

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 added in v0.36.0

type RootModule struct{}

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 added in v0.18.0

func New() *RootModule

New returns a pointer to a new HTTP RootModule.

func (*RootModule) NewModuleInstance added in v0.36.0

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