@gatling.io/http
Version:
Gatling JS is a JavaScript/TypeScript interface for the [Gatling load testing tool](https://gatling.io/).
661 lines (660 loc) • 26.5 kB
TypeScript
import { AllowListFilter, CheckBuilder, Condition, DenyListFilter, ProtocolBuilder, Session } from "@gatling.io/core";
import { Proxy } from "./proxy";
import JvmHttpProtocolBuilder = io.gatling.javaapi.http.HttpProtocolBuilder;
/**
* DSL for building HTTP protocol configurations
*
* <p>Immutable, so all methods returns a new occurrence and leave the original unmodified.
*/
export interface HttpProtocolBuilder extends ProtocolBuilder {
/**
* Define the baseUrl that will be used as a prefix for all relative urls
*
* @param url - the base url
* @returns a new HttpProtocolBuilder instance
*/
baseUrl(url: string): HttpProtocolBuilder;
/**
* Define multiple baseUrls that will be used as a prefix for all relative urls. Assigned once per
* virtual user based on a round-robin strategy.
*
* @param urls - the base urls
* @returns a new HttpProtocolBuilder instance
*/
baseUrls(...urls: string[]): HttpProtocolBuilder;
/**
* Define the warmup url. Used to perform a blank HTTP request to load the classes in the
* ClassLoader so the first load test request won't have to pay for this penalty. Hit
* "https://gatling.io" by default.
*
* @param url - the warmup url
* @returns a new HttpProtocolBuilder instance
*/
warmUp(url: string): HttpProtocolBuilder;
/**
* Disable the warmup
*
* @returns a new HttpProtocolBuilder instance
*/
disableWarmUp(): HttpProtocolBuilder;
/**
* Share a global connection pool and a global {@link javax.net.ssl.SSLContext} amongst virtual
* users instead of each having its own. Makes sense if you don't want to generate mob browser
* traffic but server to server traffic.
*
* @returns a new HttpProtocolBuilder instance
*/
shareConnections(): HttpProtocolBuilder;
/**
* Define the local address to bind from
*
* @param address - the local address
* @returns a new HttpProtocolBuilder instance
*/
localAddress(address: string): HttpProtocolBuilder;
/**
* Define multiple local addresses to bind from. Assigned once per virtual user based on a
* round-robin strategy.
*
* @param addresses - the local addresses
* @returns a new HttpProtocolBuilder instance
*/
localAddresses(...addresses: string[]): HttpProtocolBuilder;
/**
* Bind from all detected local addresses. Assigned once per virtual user based on a round-robin
* strategy.
*
* @returns a new HttpProtocolBuilder instance
*/
useAllLocalAddresses(): HttpProtocolBuilder;
/**
* Bind from all detected local addresses matching at least one of the configured patterns.
* Assigned once per virtual user based on a round-robin strategy.
*
* @param patterns - some <a
* href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java Regular
* Expression</a> patterns
* @returns a new HttpProtocolBuilder instance
*/
useAllLocalAddressesMatching(...patterns: string[]): HttpProtocolBuilder;
/**
* Define an HTTP/1.1 connections per host limit for fetching concurrent resources
*
* @param max - the limit
* @returns a new HttpProtocolBuilder instance
*/
maxConnectionsPerHost(max: number): HttpProtocolBuilder;
/**
* Disable the automatic Referer header generation, based on previous requests.
*
* @returns a new HttpProtocolBuilder instance
*/
disableAutoReferer(): HttpProtocolBuilder;
/**
* Disable the automatic Origin header generation, based the request url.
*
* @returns a new HttpProtocolBuilder instance
*/
disableAutoOrigin(): HttpProtocolBuilder;
/**
* Disable HTTP caching.
*
* @returns a new HttpProtocolBuilder instance
*/
disableCaching(): HttpProtocolBuilder;
/**
* Set a header that's common to all HTTP requests
*
* @param name - the static header name
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
header(name: string, value: string): HttpProtocolBuilder;
/**
* Set a header that's common to all HTTP requests
*
* @param name - the static header name
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
header(name: string, value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set multiple headers that's common to all HTTP requests
*
* @param headers - the headers, names are static but values are expressed as a Gatling Expression
* Language String
* @returns a new HttpProtocolBuilder instance
*/
headers(headers: Record<string, string>): HttpProtocolBuilder;
/**
* Set the accept header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
acceptHeader(value: string): HttpProtocolBuilder;
/**
* Set the accept header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
acceptHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the accept-charset header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
acceptCharsetHeader(value: string): HttpProtocolBuilder;
/**
* Set the accept-charset header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
acceptCharsetHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the accept-encoding header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
acceptEncodingHeader(value: string): HttpProtocolBuilder;
/**
* Set the accept-encoding header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
acceptEncodingHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the accept-language header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
acceptLanguageHeader(value: string): HttpProtocolBuilder;
/**
* Set the accept-language header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
acceptLanguageHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the authorization header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
authorizationHeader(value: string): HttpProtocolBuilder;
/**
* Set the authorization header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
authorizationHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the connection header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
connectionHeader(value: string): HttpProtocolBuilder;
/**
* Set the connection header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
connectionHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the content-type header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
contentTypeHeader(value: string): HttpProtocolBuilder;
/**
* Set the content-type header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
contentTypeHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the do-not-track header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
doNotTrackHeader(value: string): HttpProtocolBuilder;
/**
* Set the do-not-track header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
doNotTrackHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the origin header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
originHeader(value: string): HttpProtocolBuilder;
/**
* Set the origin header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
originHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the user-agent header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
userAgentHeader(value: string): HttpProtocolBuilder;
/**
* Set the user-agent header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
userAgentHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the upgrade-insecure-requests header
*
* @param value - the header value, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
upgradeInsecureRequestsHeader(value: string): HttpProtocolBuilder;
/**
* Set the upgrade-insecure-requests header
*
* @param value - the header value, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
upgradeInsecureRequestsHeader(value: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the authorization header for Basic Auth
*
* @param username - the username, expressed as a Gatling Expression Language String
* @param password - the password, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
basicAuth(username: string, password: string): HttpProtocolBuilder;
/**
* Set the authorization header for Basic Auth
*
* @param username - the username, expressed as a Gatling Expression Language String
* @param password - the password, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
basicAuth(username: string, password: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the authorization header for Basic Auth
*
* @param username - the username, expressed as a function
* @param password - the password, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
basicAuth(username: (session: Session) => string, password: string): HttpProtocolBuilder;
/**
* Set the authorization header for Basic Auth
*
* @param username - the username, expressed as a function
* @param password - the password, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
basicAuth(username: (session: Session) => string, password: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the authorization header for Digest Auth
*
* @param username - the username, expressed as a Gatling Expression Language String
* @param password - the password, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
digestAuth(username: string, password: string): HttpProtocolBuilder;
/**
* Set the authorization header for Digest Auth
*
* @param username - the username, expressed as a Gatling Expression Language String
* @param password - the password, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
digestAuth(username: string, password: (session: Session) => string): HttpProtocolBuilder;
/**
* Set the authorization header for Digest Auth
*
* @param username - the username, expressed as a function
* @param password - the password, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
digestAuth(username: (session: Session) => string, password: string): HttpProtocolBuilder;
/**
* Set the authorization header for Digest Auth
*
* @param username - the username, expressed as a function
* @param password - the password, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
digestAuth(username: (session: Session) => string, password: (session: Session) => string): HttpProtocolBuilder;
/**
* Instruct the reporting engine to not report resources
*
* @returns a new HttpProtocolBuilder instance
*/
silentResources(): HttpProtocolBuilder;
/**
* Instruct the reporting engine to not report requests whose uri matches the configured <a
* href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java Regular
* Expression</a> pattern
*
* @param pattern - the regex pattern
* @returns a new HttpProtocolBuilder instance
*/
silentUri(pattern: string): HttpProtocolBuilder;
/**
* Disable the automatic url encoding that tries to detect unescaped reserved chars
*
* @returns a new HttpProtocolBuilder instance
*/
disableUrlEncoding(): HttpProtocolBuilder;
/**
* Provide a function to sign the requests before writing them on the wire
*
* @param calculator - the signing function
* @returns a new HttpProtocolBuilder instance
*/
/**
* Instruct sign the requests with an OAuth1 Authorization header before writing them on the wire
*
* @param consumerKey - the consumerKey, expressed as a Gatling Expression Language String
* @param clientSharedSecret - the clientSharedSecret, expressed as a Gatling Expression Language
* String
* @param token - the token, expressed as a Gatling Expression Language String
* @param tokenSecret - the tokenSecret, expressed as a Gatling Expression Language String
* @returns a new HttpProtocolBuilder instance
*/
signWithOAuth1(consumerKey: string, clientSharedSecret: string, token: string, tokenSecret: string): HttpProtocolBuilder;
/**
* Instruct sign the requests with OAuth1 before writing them on the wire
*
* @param consumerKey - the consumerKey, expressed as a Gatling Expression Language String
* @param clientSharedSecret - the clientSharedSecret, expressed as a Gatling Expression Language
* String
* @param token - the token, expressed as a Gatling Expression Language String
* @param tokenSecret - the tokenSecret, expressed as a Gatling Expression Language String
* @param useAuthorizationHeader - if true, sign with an Authorization header, otherwise sign forms
* with extra parameters and other requests with extra query params
* @returns a new HttpProtocolBuilder instance
*/
signWithOAuth1(consumerKey: string, clientSharedSecret: string, token: string, tokenSecret: string, useAuthorizationHeader: boolean): HttpProtocolBuilder;
/**
* Instruct sign the requests with an OAuth1 Authorization before writing them on the wire
*
* @param consumerKey - the consumerKey, expressed as a function
* @param clientSharedSecret - the clientSharedSecret, expressed as a function
* @param token - the token, expressed as a function
* @param tokenSecret - the tokenSecret, expressed as a function
* @returns a new HttpProtocolBuilder instance
*/
signWithOAuth1(consumerKey: (session: Session) => string, clientSharedSecret: (session: Session) => string, token: (session: Session) => string, tokenSecret: (session: Session) => string): HttpProtocolBuilder;
/**
* Instruct sign the requests with OAuth1 before writing them on the wire
*
* @param consumerKey - the consumerKey, expressed as a function
* @param clientSharedSecret - the clientSharedSecret, expressed as a function
* @param token - the token, expressed as a function
* @param tokenSecret - the tokenSecret, expressed as a function
* @param useAuthorizationHeader - if true, sign with an Authorization header, otherwise sign forms
* with extra parameters and other requests with extra query params
* @returns a new HttpProtocolBuilder instance
*/
signWithOAuth1(consumerKey: (session: Session) => string, clientSharedSecret: (session: Session) => string, token: (session: Session) => string, tokenSecret: (session: Session) => string, useAuthorizationHeader: boolean): HttpProtocolBuilder;
/**
* Enable HTTP/2
*
* @returns a new HttpProtocolBuilder instance
*/
enableHttp2(): HttpProtocolBuilder;
/**
* Define the remote hosts that are known to support or not support HTTP/2
*
* @param remotes - the known remote hosts
* @returns a new HttpProtocolBuilder instance
*/
http2PriorKnowledge(remotes: Record<string, boolean>): HttpProtocolBuilder;
/**
* Disable automatically following redirects
*
* @returns a new HttpProtocolBuilder instance
*/
disableFollowRedirect(): HttpProtocolBuilder;
/**
* Define the maximum number of redirects in a redirect chain
*
* @param max - the limit
* @returns a new HttpProtocolBuilder instance
*/
maxRedirects(max: number): HttpProtocolBuilder;
/**
* Apply 302 strictly and not switch to GET and re-send the request body
*
* @returns a new HttpProtocolBuilder instance
*/
strict302Handling(): HttpProtocolBuilder;
/**
* Define a transformation function to be applied on the {@link Response}s before checks are
* applied. Typically used for decoding responses, eg with <a
* href="https://developers.google.com/protocol-buffers">Protobuf</a>.
*
* @param f - the strategy
* @returns a new HttpProtocolBuilder instance
*/
/**
* Apply some checks
*
* @param checks - the checks
* @returns a new HttpRequestActionBuilder instance
*/
check(...checks: CheckBuilder[]): HttpProtocolBuilder;
/**
* Define some common checks to be applied on all the requests when a condition holds true.
*
* @param condition - a condition, expressed as a Gatling Expression Language String
* @returns the next DSL step
*/
checkIf(condition: string): Condition<HttpProtocolBuilder>;
/**
* Define some common checks to be applied on all the requests when a condition holds true.
*
* @param condition - a condition, expressed as a function
* @returns the next DSL step
*/
checkIf(condition: (session: Session) => boolean): Condition<HttpProtocolBuilder>;
/**
* Automatically infer resources from HTML payloads
*
* @returns a new HttpProtocolBuilder instance
*/
inferHtmlResources(): HttpProtocolBuilder;
/**
* Automatically infer resources from HTML payloads
*
* @param allow - the allow list to filter the resources
* @returns a new HttpProtocolBuilder instance
*/
inferHtmlResources(allow: AllowListFilter): HttpProtocolBuilder;
/**
* Automatically infer resources from HTML payloads
*
* @param allow - the allow list to filter the resources
* @param deny - the deny list to filter out the resources
* @returns a new HttpProtocolBuilder instance
*/
inferHtmlResources(allow: AllowListFilter, deny: DenyListFilter): HttpProtocolBuilder;
/**
* Automatically infer resources from HTML payloads
*
* @param deny - the deny list to filter out the resources
* @returns a new HttpProtocolBuilder instance
*/
inferHtmlResources(deny: DenyListFilter): HttpProtocolBuilder;
/**
* Name the inferred resources' requests based on the tail of the url
*
* @returns a new HttpProtocolBuilder instance
*/
nameInferredHtmlResourcesAfterUrlTail(): HttpProtocolBuilder;
/**
* Name the inferred resources' requests based on the absolute url
*
* @returns a new HttpProtocolBuilder instance
*/
nameInferredHtmlResourcesAfterAbsoluteUrl(): HttpProtocolBuilder;
/**
* Name the inferred resources' requests based on the relative url
*
* @returns a new HttpProtocolBuilder instance
*/
nameInferredHtmlResourcesAfterRelativeUrl(): HttpProtocolBuilder;
/**
* Name the inferred resources' requests based on the path
*
* @returns a new HttpProtocolBuilder instance
*/
nameInferredHtmlResourcesAfterPath(): HttpProtocolBuilder;
/**
* Name the inferred resources' requests based on the last element of the path
*
* @returns a new HttpProtocolBuilder instance
*/
nameInferredHtmlResourcesAfterLastPathElement(): HttpProtocolBuilder;
/**
* Define a baseUrl that will be used as a prefix for all relative WebSocket urls.
*
* @param url - the base url
* @returns a new HttpProtocolBuilder instance
*/
wsBaseUrl(url: string): HttpProtocolBuilder;
/**
* Define multiple baseUrls that will be used as a prefix for all relative WebSocket urls.
* Assigned once per virtual user based on a round-robin strategy.
*
* @param urls - the base urls
* @returns a new HttpProtocolBuilder instance
*/
wsBaseUrls(...urls: string[]): HttpProtocolBuilder;
/**
* Automatically reconnect disconnected WebSockets
*
* @returns a new HttpProtocolBuilder instance
*/
wsReconnect(): HttpProtocolBuilder;
/**
* Define a maximum number of times a WebSocket can be automatically reconnected
*
* @param max - the limit
* @returns a new HttpProtocolBuilder instance
*/
wsMaxReconnects(max: number): HttpProtocolBuilder;
/**
* Automatically reply to a TEXT frame with another TEXT frame.
*
* @param f - the function
* @returns a new HttpProtocolBuilder instance
*/
wsAutoReplyTextFrame(f: (frame: string) => string | null): HttpProtocolBuilder;
/**
* Automatically reply to a SocketIo4 ping TEXT frame with the corresponding pong TEXT frame.
*
* @returns a new HttpProtocolBuilder instance
*/
wsAutoReplySocketIo4(): HttpProtocolBuilder;
/**
* Set the max size of the buffer for unmatched/unchecked inbound WebSocket messages. 0 by
* default, meaning such messages are not buffered.
*
* @param max - the max size
* @returns a new HttpProtocolBuilder instance
*/
wsUnmatchedInboundMessageBufferSize(max: number): HttpProtocolBuilder;
/**
* Set the max size of the buffer for unmatched/unchecked inbound SSE messages. 0 by default,
* meaning such messages are not buffered.
*
* @param max - the max size
* @returns a new HttpProtocolBuilder instance
*/
sseUnmatchedInboundMessageBufferSize(max: number): HttpProtocolBuilder;
/**
* Define a Proxy to be used for all requests
*
* @param proxy - the proxy
* @returns a new HttpProtocolBuilder instance
*/
proxy(proxy: Proxy): HttpProtocolBuilder;
/**
* Ignore any configured proxy for some hosts
*
* @param hosts - the hosts that must be connected directly without the proxy
* @returns a new HttpProtocolBuilder instance
*/
noProxyFor(...hosts: string[]): HttpProtocolBuilder;
/**
* Enable Proxy Protocol for IPv4
*
* @param address - a fake local address in IPv4 format
* @returns a new HttpProtocolBuilder instance
*/
proxyProtocolSourceIpV4Address(address: string): HttpProtocolBuilder;
/**
* Enable Proxy Protocol for IPv4
*
* @param address - a fake local address in IPv4 format
* @returns a new HttpProtocolBuilder instance
*/
proxyProtocolSourceIpV4Address(address: (session: Session) => string): HttpProtocolBuilder;
/**
* Enable Proxy Protocol for IPv6
*
* @param address - a fake local address in IPv6 format
* @returns a new HttpProtocolBuilder instance
*/
proxyProtocolSourceIpV6Address(address: string): HttpProtocolBuilder;
/**
* Enable Proxy Protocol for IPv6
*
* @param address - a fake local address in IPv6 format
* @returns a new HttpProtocolBuilder instance
*/
proxyProtocolSourceIpV6Address(address: (session: Session) => string): HttpProtocolBuilder;
/**
* Enable Gatling non-blocking DNS resolution instead of using Java's blocking implementation
*
* @param dnsServers - the DNS servers
* @returns a new HttpProtocolBuilder instance
*/
asyncNameResolution(...dnsServers: string[]): HttpProtocolBuilder;
/**
* Define some aliases to bypass DNS name resolution
*
* @param aliases - the aliases
* @returns a new HttpProtocolBuilder instance
*/
hostNameAliases(aliases: Record<string, string[]>): HttpProtocolBuilder;
/**
* Force each virtual user to have its own DNS cache and perform its own DNS resolutions instead
* of using a global shared resolver
*
* @returns a new HttpProtocolBuilder instance
*/
perUserNameResolution(): HttpProtocolBuilder;
}
export declare const wrapHttpProtocolBuilder: (_underlying: JvmHttpProtocolBuilder) => HttpProtocolBuilder;