http

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP_METHOD_GET     = "GET"
	HTTP_METHOD_POST    = "POST"
	HTTP_METHOD_PUT     = "PUT"
	HTTP_METHOD_DELETE  = "DELETE"
	HTTP_METHOD_HEAD    = "HEAD"
	HTTP_METHOD_PATCH   = "PATCH"
	HTTP_METHOD_OPTIONS = "OPTIONS"
)

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

Functions

func ToURL added in v0.18.2

func ToURL(u interface{}) (httpext.URL, error)

ToURL tries to convert anything passed to it to a k6 URL struct

Types

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

type GlobalHTTP struct{}

GlobalHTTP is a global HTTP module for a k6 instance/test run

func (*GlobalHTTP) NewModuleInstancePerVU added in v0.31.0

func (g *GlobalHTTP) NewModuleInstancePerVU() interface{}

NewModuleInstancePerVU returns an HTTP instance for each VU

type HTTP

type HTTP struct {
	SSL_3_0                            string `js:"SSL_3_0"`
	TLS_1_0                            string `js:"TLS_1_0"`
	TLS_1_1                            string `js:"TLS_1_1"`
	TLS_1_2                            string `js:"TLS_1_2"`
	TLS_1_3                            string `js:"TLS_1_3"`
	OCSP_STATUS_GOOD                   string `js:"OCSP_STATUS_GOOD"`
	OCSP_STATUS_REVOKED                string `js:"OCSP_STATUS_REVOKED"`
	OCSP_STATUS_SERVER_FAILED          string `js:"OCSP_STATUS_SERVER_FAILED"`
	OCSP_STATUS_UNKNOWN                string `js:"OCSP_STATUS_UNKNOWN"`
	OCSP_REASON_UNSPECIFIED            string `js:"OCSP_REASON_UNSPECIFIED"`
	OCSP_REASON_KEY_COMPROMISE         string `js:"OCSP_REASON_KEY_COMPROMISE"`
	OCSP_REASON_CA_COMPROMISE          string `js:"OCSP_REASON_CA_COMPROMISE"`
	OCSP_REASON_AFFILIATION_CHANGED    string `js:"OCSP_REASON_AFFILIATION_CHANGED"`
	OCSP_REASON_SUPERSEDED             string `js:"OCSP_REASON_SUPERSEDED"`
	OCSP_REASON_CESSATION_OF_OPERATION string `js:"OCSP_REASON_CESSATION_OF_OPERATION"`
	OCSP_REASON_CERTIFICATE_HOLD       string `js:"OCSP_REASON_CERTIFICATE_HOLD"`
	OCSP_REASON_REMOVE_FROM_CRL        string `js:"OCSP_REASON_REMOVE_FROM_CRL"`
	OCSP_REASON_PRIVILEGE_WITHDRAWN    string `js:"OCSP_REASON_PRIVILEGE_WITHDRAWN"`
	OCSP_REASON_AA_COMPROMISE          string `js:"OCSP_REASON_AA_COMPROMISE"`
	// contains filtered or unexported fields
}

nolint: golint

func (*HTTP) Batch

func (h *HTTP) Batch(ctx context.Context, reqsV goja.Value) (goja.Value, 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 (*HTTP) CookieJar added in v0.18.0

func (*HTTP) CookieJar(ctx context.Context) (*HTTPCookieJar, error)

func (*HTTP) Del

func (h *HTTP) Del(ctx context.Context, url goja.Value, args ...goja.Value) (*Response, error)

Del makes an HTTP DELETE and returns a corresponding response by taking goja.Values as arguments

func (*HTTP) ExpectedStatuses added in v0.31.0

func (*HTTP) ExpectedStatuses(ctx context.Context, args ...goja.Value) *expectedStatuses

ExpectedStatuses returns expectedStatuses object based on the provided arguments. The arguments must be either integers or object of `{min: <integer>, max: <integer>}` kind. The "integer"ness is checked by the Number.isInteger.

func (*HTTP) File added in v0.20.0

func (h *HTTP) File(ctx context.Context, data interface{}, args ...string) FileData

File returns a FileData parameter

func (*HTTP) Get

func (h *HTTP) Get(ctx context.Context, url goja.Value, args ...goja.Value) (*Response, error)

Get makes an HTTP GET request and returns a corresponding response by taking goja.Values as arguments

func (*HTTP) Head

func (h *HTTP) Head(ctx context.Context, url goja.Value, args ...goja.Value) (*Response, error)

Head makes an HTTP HEAD request and returns a corresponding response by taking goja.Values as arguments

func (*HTTP) Options added in v0.19.0

func (h *HTTP) Options(ctx context.Context, url goja.Value, args ...goja.Value) (*Response, error)

Options makes an HTTP OPTIONS request and returns a corresponding response by taking goja.Values as arguments

func (*HTTP) Patch

func (h *HTTP) Patch(ctx context.Context, url goja.Value, args ...goja.Value) (*Response, error)

Patch makes a patch request and returns a corresponding response by taking goja.Values as arguments

func (*HTTP) Post

func (h *HTTP) Post(ctx context.Context, url goja.Value, args ...goja.Value) (*Response, error)

Post makes an HTTP POST request and returns a corresponding response by taking goja.Values as arguments

func (*HTTP) Put

func (h *HTTP) Put(ctx context.Context, url goja.Value, args ...goja.Value) (*Response, error)

Put makes an HTTP PUT request and returns a corresponding response by taking goja.Values as arguments

func (*HTTP) Request

func (h *HTTP) Request(ctx context.Context, 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 (*HTTP) SetResponseCallback added in v0.31.0

func (h *HTTP) SetResponseCallback(ctx context.Context, 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

func (*HTTP) URL added in v0.24.0

func (http *HTTP) URL(parts []string, pieces ...string) (httpext.URL, error)

URL creates new URL from the provided parts

func (*HTTP) XCookieJar added in v0.18.0

func (*HTTP) XCookieJar(ctx *context.Context) *HTTPCookieJar

type HTTPCookieJar added in v0.18.0

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

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

func (HTTPCookieJar) CookiesForURL added in v0.18.0

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

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

func (HTTPCookieJar) Set added in v0.18.0

func (j HTTPCookieJar) 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 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

Jump to

Keyboard shortcuts

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