@gatling.io/http 3.11.7 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/checks.ts ADDED
@@ -0,0 +1,142 @@
1
+ import { HttpDsl, HttpDsl as JvmHttpDsl } from "@gatling.io/jvm-types";
2
+ import {
3
+ underlyingSessionTo,
4
+ wrapCheckBuilderCaptureGroup,
5
+ wrapCheckBuilderFind,
6
+ wrapCheckBuilderMultipleFind,
7
+ CheckBuilderCaptureGroup,
8
+ CheckBuilderFind,
9
+ CheckBuilderMultipleFind,
10
+ Expression,
11
+ Session
12
+ } from "@gatling.io/core";
13
+
14
+ import JvmCheckBuilderFind = io.gatling.javaapi.core.CheckBuilder$Find;
15
+
16
+ /**
17
+ * Bootstrap a check that capture the response location, eg the landing url in a chain of
18
+ * redirects
19
+ *
20
+ * @returns the next step in the check DSL
21
+ */
22
+ export const currentLocation = (): CheckBuilderFind<string> => wrapCheckBuilderFind(JvmHttpDsl.currentLocation());
23
+
24
+ export interface CurrentLocationRegexFunction {
25
+ /**
26
+ * Bootstrap a check that capture some <a
27
+ * href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java Regular
28
+ * Expression</a> capture groups on the response location, eg the landing url in a chain of
29
+ * redirects
30
+ *
31
+ * @param pattern - the regular expression, expressed as a Gatling Expression Language String
32
+ * @returns the next step in the check DSL
33
+ */
34
+ (pattern: string): CheckBuilderCaptureGroup;
35
+
36
+ /**
37
+ * Bootstrap a check that capture some <a
38
+ * href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java Regular
39
+ * Expression</a> capture groups on the response location, eg the landing url in a chain of
40
+ * redirects
41
+ *
42
+ * @param pattern - the regular expression, expressed as a function
43
+ * @returns the next step in the check DSL
44
+ */
45
+ (pattern: (session: Session) => string): CheckBuilderCaptureGroup;
46
+ }
47
+
48
+ export const currentLocationRegex: CurrentLocationRegexFunction = (pattern: Expression<string>) =>
49
+ wrapCheckBuilderCaptureGroup(
50
+ typeof pattern === "function"
51
+ ? JvmHttpDsl.currentLocationRegex(underlyingSessionTo(pattern))
52
+ : JvmHttpDsl.currentLocationRegex(pattern)
53
+ );
54
+
55
+ export interface HeaderFunction {
56
+ /**
57
+ * Bootstrap a check that capture the value of a HTTP header
58
+ *
59
+ * @param name the name of the HTTP header, expressed as a Gatling Expression Language String
60
+ * @return the next step in the check DSL
61
+ */
62
+ (name: string): CheckBuilderMultipleFind<string>;
63
+
64
+ /**
65
+ * Bootstrap a check that capture the value of a HTTP header
66
+ *
67
+ * @param name - the name of the HTTP header, expressed as a function
68
+ * @returns the next step in the check DSL
69
+ */
70
+ (name: (session: Session) => string): CheckBuilderMultipleFind<string>;
71
+ }
72
+
73
+ export const header: HeaderFunction = (name: Expression<string>) =>
74
+ wrapCheckBuilderMultipleFind(
75
+ typeof name === "function" ? JvmHttpDsl.header(underlyingSessionTo(name)) : JvmHttpDsl.header(name)
76
+ );
77
+
78
+ export interface HeaderRegexFunction {
79
+ /**
80
+ * Bootstrap a check that capture some <a
81
+ * href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java Regular
82
+ * Expression</a> capture groups on a response header
83
+ *
84
+ * @param name - the name of the HTTP header, expressed as a Gatling Expression Language String
85
+ * @param pattern - the regular expression, expressed as a Gatling Expression Language String
86
+ * @returns the next step in the check DSL
87
+ */
88
+ (name: string, pattern: string): CheckBuilderCaptureGroup;
89
+
90
+ /**
91
+ * Bootstrap a check that capture some <a
92
+ * href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java Regular
93
+ * Expression</a> capture groups on a response header
94
+ *
95
+ * @param name - the name of the HTTP header, expressed as a function
96
+ * @param pattern - the regular expression, expressed as a Gatling Expression Language String
97
+ * @returns the next step in the check DSL
98
+ */
99
+ (name: (session: Session) => string, pattern: string): CheckBuilderCaptureGroup;
100
+
101
+ /**
102
+ * Bootstrap a check that capture some <a
103
+ * href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java Regular
104
+ * Expression</a> capture groups on a response header
105
+ *
106
+ * @param name - the name of the HTTP header, expressed as a Gatling Expression Language String
107
+ * @param pattern - the regular expression, expressed as a function
108
+ * @returns the next step in the check DSL
109
+ */
110
+ (name: string, pattern: (session: Session) => string): CheckBuilderCaptureGroup;
111
+
112
+ /**
113
+ * Bootstrap a check that capture some <a
114
+ * href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">Java Regular
115
+ * Expression</a> capture groups on a response header
116
+ *
117
+ * @param name the name of the HTTP header, expressed as a function
118
+ * @param pattern the regular expression, expressed as a function
119
+ * @return the next step in the check DSL
120
+ */
121
+ (name: (session: Session) => string, pattern: (session: Session) => string): CheckBuilderCaptureGroup;
122
+ }
123
+
124
+ export const headerRegex: HeaderRegexFunction = (name: Expression<string>, pattern: Expression<string>) =>
125
+ wrapCheckBuilderCaptureGroup(
126
+ typeof name === "function"
127
+ ? typeof pattern === "function"
128
+ ? HttpDsl.headerRegex(underlyingSessionTo(name), underlyingSessionTo(pattern))
129
+ : HttpDsl.headerRegex(underlyingSessionTo(name), pattern)
130
+ : typeof pattern === "function"
131
+ ? HttpDsl.headerRegex(name, underlyingSessionTo(pattern))
132
+ : // FIXME forced to use the charsequence version
133
+ HttpDsl.headerRegex(name, pattern)
134
+ );
135
+
136
+ /**
137
+ * Bootstrap a check that capture the response HTTP status code
138
+ *
139
+ * @returns the next step in the check DSL
140
+ */
141
+ export const status = (): CheckBuilderFind<number> =>
142
+ wrapCheckBuilderFind(JvmHttpDsl.status() as JvmCheckBuilderFind<number>);
package/src/cookies.ts ADDED
@@ -0,0 +1,227 @@
1
+ import { ActionBuilder, Expression, Session, underlyingSessionTo, wrapActionBuilder, Wrapper } from "@gatling.io/core";
2
+ import { HttpDsl as JvmHttpDsl } from "@gatling.io/jvm-types";
3
+
4
+ import JvmAddCookie = io.gatling.javaapi.http.AddCookie;
5
+ import JvmGetCookie = io.gatling.javaapi.http.GetCookie;
6
+
7
+ /**
8
+ * DSL for adding a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies">cookie</a>
9
+ * in the virtual user's CookieJar instead of having the server send a Set-Cookie header.
10
+ *
11
+ * <p>Immutable, so all methods return a new occurrence and leave the original unmodified.
12
+ */
13
+ export interface AddCookie extends Wrapper<JvmAddCookie> {
14
+ /**
15
+ * Define the domain of the cookie. If undefined, will try to use the domain of {@link
16
+ * HttpProtocolBuilder#baseUrl(String)}
17
+ *
18
+ * @param domain - the cookie domain
19
+ * @returns a new AddCookie
20
+ */
21
+ withDomain(domain: string): AddCookie;
22
+
23
+ /**
24
+ * Define the path of the cookie.
25
+ *
26
+ * @param path - the cookie path
27
+ * @returns a new AddCookie
28
+ */
29
+ withPath(path: string): AddCookie;
30
+
31
+ /**
32
+ * Define the maxAge attribute of the cookie.
33
+ *
34
+ * @param maxAge - the cookie maxAge
35
+ * @returns a new AddCookie
36
+ */
37
+ withMaxAge(maxAge: number): AddCookie;
38
+
39
+ /**
40
+ * Define the secure attribute of the cookie.
41
+ *
42
+ * @param secure - if the cookie must only be sent with HTTPS requests
43
+ * @returns a new AddCookie
44
+ */
45
+ withSecure(secure: boolean): AddCookie;
46
+ }
47
+
48
+ const wrapAddCookie = (_underlying: JvmAddCookie): AddCookie => ({
49
+ _underlying,
50
+ withDomain: (domain: string): AddCookie => wrapAddCookie(_underlying.withDomain(domain)),
51
+ withPath: (path: string): AddCookie => wrapAddCookie(_underlying.withPath(path)),
52
+ withMaxAge: (maxAge: number): AddCookie => wrapAddCookie(_underlying.withMaxAge(maxAge)),
53
+ withSecure: (secure: boolean): AddCookie => wrapAddCookie(_underlying.withSecure(secure))
54
+ });
55
+
56
+ /**
57
+ * DSL for fetching the value of a <a
58
+ * href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies">cookie</a> from the virtual
59
+ * user's CookieJar into its {@link Session}.
60
+ *
61
+ * <p>Immutable, so all methods return a new occurrence and leave the original unmodified.
62
+ */
63
+ export interface GetCookie extends Wrapper<JvmGetCookie> {
64
+ /**
65
+ * Define the domain of the cookie. If undefined, will try to use the domain of {@link
66
+ * HttpProtocolBuilder#baseUrl(String)}
67
+ *
68
+ * @param domain - the cookie domain, expressed as a Gatling Expression Language String
69
+ * @returns a new GetCookie
70
+ */
71
+ withDomain(domain: string): GetCookie;
72
+
73
+ /**
74
+ * Define the domain of the cookie. If undefined, will try to use the domain of {@link
75
+ * HttpProtocolBuilder#baseUrl(String)}
76
+ *
77
+ * @param domain - the cookie domain, expressed as a function
78
+ * @returns a new GetCookie
79
+ */
80
+ withDomain(domain: (session: Session) => string): GetCookie;
81
+
82
+ /**
83
+ * Define the path of the cookie.
84
+ *
85
+ * @param path - the cookie path
86
+ * @returns a new GetCookie
87
+ */
88
+ withPath(path: string): GetCookie;
89
+
90
+ /**
91
+ * Define the secure attribute of the cookie.
92
+ *
93
+ * @param secure - the cookie secure attribute
94
+ * @returns a new GetCookie
95
+ */
96
+ withSecure(secure: boolean): GetCookie;
97
+
98
+ /**
99
+ * Define the {@link Session} key to save the cookie value. If undefined, will use the cookie name
100
+ *
101
+ * @param saveAs - the key
102
+ * @returns a new GetCookie
103
+ */
104
+ saveAs(saveAs: string): GetCookie;
105
+ }
106
+
107
+ const wrapGetCookie = (_underlying: JvmGetCookie): GetCookie => ({
108
+ _underlying,
109
+ withDomain: (domain: Expression<string>): GetCookie =>
110
+ wrapGetCookie(
111
+ typeof domain === "function" ? _underlying.withDomain(underlyingSessionTo(domain)) : _underlying.withPath(domain)
112
+ ),
113
+ withPath: (path: string): GetCookie => wrapGetCookie(_underlying.withPath(path)),
114
+ withSecure: (secure: boolean): GetCookie => wrapGetCookie(_underlying.withSecure(secure)),
115
+ saveAs: (saveAs: string): GetCookie => wrapGetCookie(_underlying.saveAs(saveAs))
116
+ });
117
+
118
+ /**
119
+ * Create an action to add a Cookie
120
+ *
121
+ * @param cookie - the DSL for adding a cookie
122
+ * @returns an ActionBuilder
123
+ */
124
+ export const addCookie = (cookie: AddCookie): ActionBuilder =>
125
+ wrapActionBuilder(JvmHttpDsl.addCookie(cookie._underlying));
126
+
127
+ /**
128
+ * Create an action to get a Cookie value into the Session
129
+ *
130
+ * @param cookie - the DSL for getting a cookie
131
+ * @returns an ActionBuilder
132
+ */
133
+ export const getCookieValue = (cookie: GetCookie): ActionBuilder =>
134
+ wrapActionBuilder(JvmHttpDsl.getCookieValue(cookie._underlying));
135
+
136
+ /**
137
+ * Create an action to flush the Session (non-persistent) Cookies of the user
138
+ *
139
+ * @returns an ActionBuilder
140
+ */
141
+ export const flushSessionCookies = (): ActionBuilder => wrapActionBuilder(JvmHttpDsl.flushSessionCookies());
142
+
143
+ /**
144
+ * Create an action to flush all the Cookies of the user
145
+ *
146
+ * @returns an ActionBuilder
147
+ */
148
+ export const flushCookieJar = (): ActionBuilder => wrapActionBuilder(JvmHttpDsl.flushCookieJar());
149
+
150
+ /**
151
+ * Create an action to flush the HTTP cache of the user
152
+ *
153
+ * @returns an ActionBuilder
154
+ */
155
+ export const flushHttpCache = (): ActionBuilder => wrapActionBuilder(JvmHttpDsl.flushHttpCache());
156
+
157
+ export interface CookieApply {
158
+ /**
159
+ * Bootstrap the DSL for defining a Cookie to add
160
+ *
161
+ * @param name - the name of the cookie, expressed as a Gatling Expression Language String
162
+ * @param value - the value of the cookie, expressed as a Gatling Expression Language String
163
+ * @returns the next DSL step
164
+ */
165
+ (name: string, value: string): AddCookie;
166
+
167
+ /**
168
+ * Bootstrap the DSL for defining a Cookie to add
169
+ *
170
+ * @param name - the name of the cookie, expressed as a function
171
+ * @param value - the value of the cookie, expressed as a Gatling Expression Language String
172
+ * @returns the next DSL step
173
+ */
174
+ (name: string, value: (session: Session) => string): AddCookie;
175
+
176
+ /**
177
+ * Bootstrap the DSL for defining a Cookie to add
178
+ *
179
+ * @param name - the name of the cookie, expressed as a Gatling Expression Language String
180
+ * @param value - the value of the cookie, expressed as a function
181
+ * @returns the next DSL step
182
+ */
183
+ (name: (session: Session) => string, value: string): AddCookie;
184
+
185
+ /**
186
+ * Bootstrap the DSL for defining a Cookie to add
187
+ *
188
+ * @param name - the name of the cookie, expressed as a function
189
+ * @param value - the value of the cookie, expressed as a function
190
+ * @returns the next DSL step
191
+ */
192
+ (name: (session: Session) => string, value: (session: Session) => string): AddCookie;
193
+ }
194
+
195
+ export const Cookie: CookieApply = (name: Expression<string>, value: Expression<string>): AddCookie =>
196
+ wrapAddCookie(
197
+ typeof name === "function"
198
+ ? typeof value === "function"
199
+ ? JvmHttpDsl.Cookie(underlyingSessionTo(name), underlyingSessionTo(value))
200
+ : JvmHttpDsl.Cookie(underlyingSessionTo(name), value)
201
+ : typeof value === "function"
202
+ ? JvmHttpDsl.Cookie(name, underlyingSessionTo(value))
203
+ : JvmHttpDsl.Cookie(name, value)
204
+ );
205
+
206
+ export interface CookieKeyApply {
207
+ /**
208
+ * Bootstrap the DSL for defining a Cookie to get
209
+ *
210
+ * @param name - the name of the cookie, expressed as a Gatling Expression Language String
211
+ * @returns the next DSL step
212
+ */
213
+ (name: string): GetCookie;
214
+
215
+ /**
216
+ * Bootstrap the DSL for defining a Cookie to get
217
+ *
218
+ * @param name - the name of the cookie, expressed as a function
219
+ * @returns the next DSL step
220
+ */
221
+ (name: (session: Session) => string): GetCookie;
222
+ }
223
+
224
+ export const CookieKey: CookieKeyApply = (name: Expression<string>): GetCookie =>
225
+ wrapGetCookie(
226
+ typeof name === "function" ? JvmHttpDsl.CookieKey(underlyingSessionTo(name)) : JvmHttpDsl.CookieKey(name)
227
+ );
package/src/feeders.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { HttpDsl as JvmHttpDsl } from "@gatling.io/jvm-types";
2
+
3
+ import { FileBasedFeederBuilder, wrapFileBasedFeederBuilder } from "@gatling.io/core";
4
+
5
+ /**
6
+ * Bootstrap a feeder that reads from a sitemap XML file
7
+ *
8
+ * @param filePath - the path of the file, either relative to the root of the classpath, or absolute, expressed as a
9
+ * Gatling Expression Language String
10
+ * @returns the next DSL step
11
+ */
12
+ export const sitemap = (filePath: string): FileBasedFeederBuilder<string> =>
13
+ wrapFileBasedFeederBuilder(JvmHttpDsl.sitemap(filePath));
package/src/headers.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { Wrapper } from "@gatling.io/core";
2
+
3
+ import JvmHttpHeaders = io.netty.handler.codec.http.HttpHeaders;
4
+
5
+ /**
6
+ * Provides the constants for the standard HTTP header names and values and
7
+ * commonly used utility methods that accesses an {@link HttpMessage}.
8
+ * <p>
9
+ * Concrete instances of this class are most easily obtained from its default factory:
10
+ * {@link DefaultHttpHeadersFactory#headersFactory()}.
11
+ */
12
+ export interface HttpHeaders extends Wrapper<JvmHttpHeaders> {
13
+ /**
14
+ * Adds a new header with the specified name and value.
15
+ *
16
+ * If the specified value is not a {@link String}, it is converted
17
+ * into a {@link String} by {@link Object#toString()}, except in the cases
18
+ * of {@link Date} and {@link Calendar}, which are formatted to the date
19
+ * format defined in <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>.
20
+ *
21
+ * @param name - The name of the header being added
22
+ * @param value - The value of the header being added
23
+ *
24
+ * @returns {@code this}
25
+ */
26
+ add(name: string, value: any): HttpHeaders;
27
+ }
28
+
29
+ export const wrapHttpHeaders = (_underlying: JvmHttpHeaders): HttpHeaders => ({
30
+ _underlying,
31
+ add: (name: string, value: any): HttpHeaders => wrapHttpHeaders(_underlying.add(name, value))
32
+ });