http

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: AGPL-3.0 Imports: 33 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

This section is empty.

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 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"`
	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"`
}

func New added in v0.18.0

func New() *HTTP

func (*HTTP) Batch

func (h *HTTP) Batch(ctx context.Context, reqsV goja.Value) (goja.Value, 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) (*HTTPResponse, error)

func (*HTTP) File added in v0.20.0

func (h *HTTP) File(data []byte, args ...string) FileData

File returns a FileData parameter

func (*HTTP) Get

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

func (*HTTP) Head

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

func (*HTTP) Options added in v0.19.0

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

func (*HTTP) Patch

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

func (*HTTP) Post

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

func (*HTTP) Put

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

func (*HTTP) Request

func (h *HTTP) Request(ctx context.Context, method string, url goja.Value, args ...goja.Value) (*HTTPResponse, error)

func (*HTTP) Url added in v0.16.0

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

func (*HTTP) XCookieJar added in v0.18.0

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

type HTTPCookie added in v0.18.0

type HTTPCookie struct {
	Name, Value, Domain, Path string
	HttpOnly, Secure          bool
	MaxAge                    int
	Expires                   int64
}

type HTTPCookieJar added in v0.18.0

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

func (HTTPCookieJar) CookiesForURL added in v0.18.0

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

func (HTTPCookieJar) Set added in v0.18.0

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

type HTTPRequest added in v0.20.0

type HTTPRequest struct {
	Method  string                          `json:"method"`
	URL     string                          `json:"url"`
	Headers map[string][]string             `json:"headers"`
	Body    string                          `json:"body"`
	Cookies map[string][]*HTTPRequestCookie `json:"cookies"`
}

type HTTPRequestCookie added in v0.18.0

type HTTPRequestCookie struct {
	Name, Value string
	Replace     bool
}

type HTTPResponse

type HTTPResponse struct {
	RemoteIP       string                   `json:"remote_ip"`
	RemotePort     int                      `json:"remote_port"`
	URL            string                   `json:"url"`
	Status         int                      `json:"status"`
	Proto          string                   `json:"proto"`
	Headers        map[string]string        `json:"headers"`
	Cookies        map[string][]*HTTPCookie `json:"cookies"`
	Body           interface{}              `json:"body"`
	Timings        HTTPResponseTimings      `json:"timings"`
	TLSVersion     string                   `json:"tls_version"`
	TLSCipherSuite string                   `json:"tls_cipher_suite"`
	OCSP           netext.OCSP              `js:"ocsp" json:"ocsp"`
	Error          string                   `json:"error"`
	Request        HTTPRequest              `json:"request"`
	// contains filtered or unexported fields
}
func (res *HTTPResponse) ClickLink(args ...goja.Value) (*HTTPResponse, error)

func (*HTTPResponse) Html

func (res *HTTPResponse) Html(selector ...string) html.Selection

func (*HTTPResponse) Json

func (res *HTTPResponse) Json(selector ...string) goja.Value

func (*HTTPResponse) SubmitForm added in v0.19.0

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

type HTTPResponseTimings

type HTTPResponseTimings struct {
	Duration       float64 `json:"duration"`
	Blocked        float64 `json:"blocked"`
	LookingUp      float64 `json:"looking_up"`
	Connecting     float64 `json:"connecting"`
	TLSHandshaking float64 `json:"tls_handshaking"`
	Sending        float64 `json:"sending"`
	Waiting        float64 `json:"waiting"`
	Receiving      float64 `json:"receiving"`
}

type MultiSlotLimiter added in v0.19.0

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

MultiSlotLimiter can restrict the concurrent execution of different groups of tasks to the given `slots` limit. Each group is represented with a string ID.

func NewMultiSlotLimiter added in v0.19.0

func NewMultiSlotLimiter(slots int) *MultiSlotLimiter

NewMultiSlotLimiter initializes and returns a new MultiSlotLimiter with the given slot count

func (*MultiSlotLimiter) Slot added in v0.19.0

func (l *MultiSlotLimiter) Slot(s string) SlotLimiter

Slot is used to retrieve the corresponding slot to the given string ID. If no slot with that ID exists, it creates it and saves it for future use. It is safe to call this method concurrently.

type ResponseType added in v0.23.0

type ResponseType uint

ResponseType is used in the request to specify how the response body should be treated The conversion and validation methods are auto-generated with https://github.com/alvaroloes/enumer:

const (
	// ResponseTypeText causes k6 to return the response body as a string. It works
	// well for web pages and JSON documents, but it can cause issues with
	// binary files since their data could be lost when they're converted in the
	// UTF-16 strings JavaScript uses.
	// This is the default value for backwards-compatibility, unless the global
	// discardResponseBodies option is enabled.
	ResponseTypeText ResponseType = iota
	// ResponseTypeBinary causes k6 to return the response body as a []byte, suitable
	// for working with binary files without lost data and needless string conversions.
	ResponseTypeBinary
	// ResponseTypeNone causes k6 to fully read the response body while immediately
	// discarding the actual data - k6 would set the body of the returned HTTPResponse
	// to null. This saves CPU and memory and is suitable for HTTP requests that we just
	// want to  measure, but we don't care about their responses' contents. This is the
	// default value for all requests if the global discardResponseBodies is enablled.
	ResponseTypeNone
)

func ResponseTypeString added in v0.23.0

func ResponseTypeString(s string) (ResponseType, error)

ResponseTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ResponseTypeValues added in v0.23.0

func ResponseTypeValues() []ResponseType

ResponseTypeValues returns all values of the enum

func (ResponseType) IsAResponseType added in v0.23.0

func (i ResponseType) IsAResponseType() bool

IsAResponseType returns "true" if the value is listed in the enum definition. "false" otherwise

func (ResponseType) MarshalJSON added in v0.23.0

func (i ResponseType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ResponseType

func (ResponseType) MarshalText added in v0.23.0

func (i ResponseType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for ResponseType

func (ResponseType) String added in v0.23.0

func (i ResponseType) String() string

func (*ResponseType) UnmarshalJSON added in v0.23.0

func (i *ResponseType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ResponseType

func (*ResponseType) UnmarshalText added in v0.23.0

func (i *ResponseType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for ResponseType

type SlotLimiter added in v0.18.2

type SlotLimiter chan struct{}

SlotLimiter can restrict the concurrent execution of tasks to the given `slots` limit

func NewSlotLimiter added in v0.18.2

func NewSlotLimiter(slots int) SlotLimiter

NewSlotLimiter initializes and returns a new SlotLimiter with the given slot count

func (SlotLimiter) Begin added in v0.18.2

func (sl SlotLimiter) Begin()

Begin uses up a slot to denote the start of a task exeuction. It's a noop if the number of slots is 0, and if no slots are available, it blocks and waits.

func (SlotLimiter) End added in v0.18.2

func (sl SlotLimiter) End()

End restores a slot and should be called at the end of a taks execution, preferably from a defer statement right after Begin()

type URL added in v0.18.2

type URL struct {
	URL       *url.URL `js:"-"`
	Name      string   `js:"name"` // http://example.com/thing/${}/
	URLString string   `js:"url"`  // http://example.com/thing/1234/
}

A URL wraps net.URL, and preserves the template (if any) the URL was constructed from.

func ToURL added in v0.18.2

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

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

Jump to

Keyboard shortcuts

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