@gatling.io/http 3.11.7 → 3.13.1

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.
@@ -0,0 +1,838 @@
1
+ import {
2
+ ActionBuilder,
3
+ Body,
4
+ CheckBuilder,
5
+ Condition,
6
+ Duration,
7
+ Expression,
8
+ Session,
9
+ SessionTo,
10
+ asJava,
11
+ toJvmDuration,
12
+ underlyingSessionTo,
13
+ underlyingSessionToJava,
14
+ wrapCondition
15
+ } from "@gatling.io/core";
16
+
17
+ import { BodyPart } from "../bodyPart";
18
+ import { Proxy } from "../proxy";
19
+
20
+ import JvmHttpRequestActionBuilder = io.gatling.javaapi.http.HttpRequestActionBuilder;
21
+
22
+ export * from "./body";
23
+ export * from "./request";
24
+
25
+ export interface RequestWithParamsActionBuilder<T> {
26
+ /**
27
+ * Set some query parameter
28
+ *
29
+ * @param name - the name of the parameter, expressed as a Gatling Expression Language String
30
+ * @param value - the value of the parameter, expressed as a Gatling Expression Language String
31
+ * @returns a new DSL instance
32
+ */
33
+ queryParam(name: string, value: string): T;
34
+
35
+ /**
36
+ * Set some query parameter
37
+ *
38
+ * @param name - the name of the parameter, expressed as a Gatling Expression Language String
39
+ * @param value - the static value of the parameter
40
+ * @returns a new DSL instance
41
+ */
42
+ queryParam(name: string, value: any): T;
43
+
44
+ /**
45
+ * Set some query parameter
46
+ *
47
+ * @param name - the name of the parameter, expressed as a Gatling Expression Language String
48
+ * @param value - the value of the parameter, expressed as a function
49
+ * @returns a new DSL instance
50
+ */
51
+ queryParam(name: string, value: (session: Session) => any): T;
52
+
53
+ /**
54
+ * Set some query parameter
55
+ *
56
+ * @param name - the name of the parameter, expressed as a function
57
+ * @param value - the value of the parameter, expressed as a Gatling Expression Language String
58
+ * @returns a new DSL instance
59
+ */
60
+ queryParam(name: (session: Session) => string, value: string): T;
61
+
62
+ /**
63
+ * Set some query parameter
64
+ *
65
+ * @param name - the name of the parameter, expressed as a function
66
+ * @param value - the static value of the parameter
67
+ * @returns a new DSL instance
68
+ */
69
+ queryParam(name: (session: Session) => string, value: any): T;
70
+
71
+ /**
72
+ * Set some query parameter
73
+ *
74
+ * @param name - the name of the parameter, expressed as a function
75
+ * @param value - the value of the parameter, expressed as a function
76
+ * @returns a new DSL instance
77
+ */
78
+ queryParam(name: (session: Session) => string, value: (session: Session) => any): T;
79
+
80
+ /**
81
+ * Set a multivalued query parameter
82
+ *
83
+ * @param name - the name of the parameter, expressed as a Gatling Expression Language String
84
+ * @param values - the list of values of the parameter, expressed as a Gatling Expression Language
85
+ * String
86
+ * @returns a new DSL instance
87
+ */
88
+ multivaluedQueryParam(name: string, values: string): T;
89
+
90
+ /**
91
+ * Set a multivalued query parameter
92
+ *
93
+ * @param name - the name of the parameter, expressed as a Gatling Expression Language String
94
+ * @param values - the static list of values of the parameter
95
+ * @returns a new DSL instance
96
+ */
97
+ multivaluedQueryParam(name: string, values: any[]): T;
98
+
99
+ /**
100
+ * Set a multivalued query parameter
101
+ *
102
+ * @param name - the name of the parameter, expressed as a Gatling Expression Language String
103
+ * @param values - the list of values of the parameter, expressed as a function
104
+ * @returns a new DSL instance
105
+ */
106
+ multivaluedQueryParam(name: string, values: (session: Session) => any[]): T;
107
+
108
+ /**
109
+ * Set a multivalued query parameter
110
+ *
111
+ * @param name - the name of the parameter, expressed as a function
112
+ * @param values - the list of values of the parameter, expressed as a Gatling Expression Language
113
+ * String
114
+ * @returns a new DSL instance
115
+ */
116
+ multivaluedQueryParam(name: (session: Session) => string, values: string): T;
117
+
118
+ /**
119
+ * Set a multivalued query parameter
120
+ *
121
+ * @param name - the name of the parameter, expressed as a function
122
+ * @param values - the static list of values of the parameter
123
+ * @returns a new DSL instance
124
+ */
125
+ multivaluedQueryParam(name: (session: Session) => string, values: any[]): T;
126
+
127
+ /**
128
+ * Set a multivalued query parameter
129
+ *
130
+ * @param name - the name of the parameter, expressed as a function
131
+ * @param values - the list of values of the parameter, expressed as a function
132
+ * @returns a new DSL instance
133
+ */
134
+ multivaluedQueryParam(name: (session: Session) => string, values: (session: Session) => any[]): T;
135
+
136
+ /**
137
+ * Set multiple query params
138
+ *
139
+ * @param map - a static Map of query params
140
+ * @returns a new DSL instance
141
+ */
142
+ queryParamMap(map: string): T;
143
+
144
+ /**
145
+ * Set multiple query params
146
+ *
147
+ * @param map - a Map of query params, expressed as a Gatling Expression Language String
148
+ * @returns a new DSL instance
149
+ */
150
+ queryParamMap(map: Record<string, any>): T;
151
+
152
+ /**
153
+ * Set multiple query params
154
+ *
155
+ * @param map - a Map of query params, expressed as a function
156
+ * @returns a new DSL instance
157
+ */
158
+ queryParamMap(map: (session: Session) => Record<string, any>): T;
159
+
160
+ /**
161
+ * Set a header
162
+ *
163
+ * @param name - the static header name
164
+ * @param value - the header value, expressed as a Gatling Expression Language String
165
+ * @returns a new DSL instance
166
+ */
167
+ header(name: string, value: string): T;
168
+
169
+ /**
170
+ * Set a header
171
+ *
172
+ * @param name - the static header name
173
+ * @param value - the header value, expressed as a function
174
+ * @returns a new DSL instance
175
+ */
176
+ header(name: string, value: (session: Session) => string): T;
177
+
178
+ /**
179
+ * Set multiple headers
180
+ *
181
+ * @param headers - the headers, names are static but values are expressed as a Gatling Expression
182
+ * Language String
183
+ * @returns a new DSL instance
184
+ */
185
+ headers(headers: Record<string, string>): T;
186
+
187
+ /**
188
+ * Ignore common headers set in the Http protocol configuration
189
+ *
190
+ * @returns a new DSL instance
191
+ */
192
+ ignoreProtocolHeaders(): T;
193
+
194
+ /**
195
+ * Set the authorization header for Basic Auth
196
+ *
197
+ * @param username - the username, expressed as a Gatling Expression Language String
198
+ * @param password - the password, expressed as a Gatling Expression Language String
199
+ * @returns a new DSL instance
200
+ */
201
+ basicAuth(username: string, password: string): T;
202
+
203
+ /**
204
+ * Set the authorization header for Basic Auth
205
+ *
206
+ * @param username - the username, expressed as a Gatling Expression Language String
207
+ * @param password - the password, expressed as a function
208
+ * @returns a new DSL instance
209
+ */
210
+ basicAuth(username: string, password: (session: Session) => string): T;
211
+
212
+ /**
213
+ * Set the authorization header for Basic Auth
214
+ *
215
+ * @param username - the username, expressed as a function
216
+ * @param password - the password, expressed as a Gatling Expression Language String
217
+ * @returns a new DSL instance
218
+ */
219
+ basicAuth(username: (session: Session) => string, password: string): T;
220
+
221
+ /**
222
+ * Set the authorization header for Basic Auth
223
+ *
224
+ * @param username - the username, expressed as a function
225
+ * @param password - the password, expressed as a function
226
+ * @returns a new DSL instance
227
+ */
228
+ basicAuth(username: (session: Session) => string, password: (session: Session) => string): T;
229
+
230
+ /**
231
+ * Set the authorization header for Digest Auth
232
+ *
233
+ * @param username - the username, expressed as a Gatling Expression Language String
234
+ * @param password - the password, expressed as a Gatling Expression Language String
235
+ * @returns a new DSL instance
236
+ */
237
+ digestAuth(username: string, password: string): T;
238
+
239
+ /**
240
+ * Set the authorization header for Digest Auth
241
+ *
242
+ * @param username - the username, expressed as a Gatling Expression Language String
243
+ * @param password - the password, expressed as a function
244
+ * @returns a new DSL instance
245
+ */
246
+ digestAuth(username: string, password: (session: Session) => string): T;
247
+
248
+ /**
249
+ * Set the authorization header for Digest Auth
250
+ *
251
+ * @param username - the username, expressed as a function
252
+ * @param password - the password, expressed as a Gatling Expression Language String
253
+ * @returns a new DSL instance
254
+ */
255
+ digestAuth(username: (session: Session) => string, password: string): T;
256
+
257
+ /**
258
+ * Set the authorization header for Digest Auth
259
+ *
260
+ * @param username - the username, expressed as a function
261
+ * @param password - the password, expressed as a function
262
+ * @returns a new DSL instance
263
+ */
264
+ digestAuth(username: (session: Session) => string, password: (session: Session) => string): T;
265
+
266
+ /**
267
+ * Disable the automatic url encoding that tries to detect unescaped reserved chars
268
+ *
269
+ * @returns a new DSL instance
270
+ */
271
+ disableUrlEncoding(): T;
272
+
273
+ /**
274
+ * Define a Proxy to be used for this request
275
+ *
276
+ * @param proxy - the proxy
277
+ * @returns a new DSL instance
278
+ */
279
+ proxy(proxy: Proxy): T;
280
+
281
+ // TODO sign
282
+
283
+ /**
284
+ * Instruct sign the request with OAuth1 before writing it on the wire
285
+ *
286
+ * @param consumerKey - the consumerKey, expressed as a Gatling Expression Language String
287
+ * @param clientSharedSecret - the clientSharedSecret, expressed as a Gatling Expression Language
288
+ * String
289
+ * @param token - the token, expressed as a Gatling Expression Language String
290
+ * @param tokenSecret - the tokenSecret, expressed as a Gatling Expression Language String
291
+ * @returns a new DSL instance
292
+ */
293
+ signWithOAuth1(consumerKey: string, clientSharedSecret: string, token: string, tokenSecret: string): T;
294
+
295
+ /**
296
+ * Instruct sign the request with OAuth1 before writing it on the wire
297
+ *
298
+ * @param consumerKey - the consumerKey, expressed as a function
299
+ * @param clientSharedSecret - the clientSharedSecret, expressed as a function
300
+ * @param token - the token, expressed as a function
301
+ * @param tokenSecret - the tokenSecret, expressed as a function
302
+ * @returns a new DSL instance
303
+ */
304
+ signWithOAuth1(
305
+ consumerKey: (session: Session) => string,
306
+ clientSharedSecret: (session: Session) => string,
307
+ token: (session: Session) => string,
308
+ tokenSecret: (session: Session) => string
309
+ ): T;
310
+ }
311
+
312
+ const requestWithParamsActionBuilderImpl = <T>(
313
+ jvmBuilder: JvmHttpRequestActionBuilder,
314
+ wrap: (_underlying: JvmHttpRequestActionBuilder) => T
315
+ ): RequestWithParamsActionBuilder<T> => ({
316
+ queryParam: (name: Expression<string>, value: string | Expression<any>): T => {
317
+ if (typeof name === "function") {
318
+ if (typeof value === "function") {
319
+ return wrap(jvmBuilder.queryParam(underlyingSessionTo(name), underlyingSessionTo(value)));
320
+ } else if (typeof value === "string") {
321
+ // FIXME it shows the value:any overload?
322
+ return wrap(jvmBuilder.queryParam(underlyingSessionTo(name), value));
323
+ } else {
324
+ // FIXME it shows the value:func overload?
325
+ return wrap(jvmBuilder.queryParam(underlyingSessionTo(name), value));
326
+ }
327
+ } else {
328
+ if (typeof value === "function") {
329
+ // FIXME it shows the value:any overload?
330
+ return wrap(jvmBuilder.queryParam(name, underlyingSessionTo(value)));
331
+ } else if (typeof value === "string") {
332
+ // FIXME it shows the value:any overload?
333
+ return wrap(jvmBuilder.queryParam(name, value));
334
+ } else {
335
+ return wrap(jvmBuilder.queryParam(name, value));
336
+ }
337
+ }
338
+ },
339
+ multivaluedQueryParam: (name: Expression<string>, values: string | Expression<any[]>): T => {
340
+ if (typeof name === "function") {
341
+ if (typeof values === "function") {
342
+ return wrap(
343
+ jvmBuilder.multivaluedQueryParam(underlyingSessionTo(name), underlyingSessionToJava(values) as any)
344
+ );
345
+ } else if (typeof values === "string") {
346
+ return wrap(jvmBuilder.multivaluedQueryParam(underlyingSessionTo(name), values));
347
+ } else {
348
+ return wrap(jvmBuilder.multivaluedQueryParam(underlyingSessionTo(name), values));
349
+ }
350
+ } else {
351
+ if (typeof values === "function") {
352
+ return wrap(jvmBuilder.multivaluedQueryParam(name, underlyingSessionToJava(values) as any));
353
+ } else if (typeof values === "string") {
354
+ return wrap(jvmBuilder.multivaluedQueryParam(name, values));
355
+ } else {
356
+ return wrap(jvmBuilder.multivaluedQueryParam(name, values));
357
+ }
358
+ }
359
+ },
360
+ queryParamMap: (map: string | Expression<Record<string, any>>): T => {
361
+ if (typeof map === "function") {
362
+ return wrap(jvmBuilder.queryParamMap(underlyingSessionToJava(map as SessionTo<Record<string, any>>)));
363
+ } else if (typeof map === "object") {
364
+ return wrap(jvmBuilder.queryParamMap(map));
365
+ } else {
366
+ return wrap(jvmBuilder.queryParamMap(map));
367
+ }
368
+ },
369
+ header: (name: string, value: Expression<string>): T =>
370
+ wrap(
371
+ typeof value === "function" ? jvmBuilder.header(name, underlyingSessionTo(value)) : jvmBuilder.header(name, value)
372
+ ),
373
+ headers: (headers: Record<string, string>): T => wrap(jvmBuilder.headers(asJava(headers) as any)),
374
+ ignoreProtocolHeaders: (): T => wrap(jvmBuilder.ignoreProtocolHeaders()),
375
+ basicAuth: (username: Expression<string>, password: Expression<string>): T =>
376
+ wrap(
377
+ typeof username === "function"
378
+ ? typeof password === "function"
379
+ ? jvmBuilder.basicAuth(underlyingSessionTo(username), underlyingSessionTo(password))
380
+ : jvmBuilder.basicAuth(underlyingSessionTo(username), password)
381
+ : typeof password === "function"
382
+ ? jvmBuilder.basicAuth(username, underlyingSessionTo(password))
383
+ : jvmBuilder.basicAuth(username, password)
384
+ ),
385
+ digestAuth: (username: Expression<string>, password: Expression<string>): T =>
386
+ wrap(
387
+ typeof username === "function"
388
+ ? typeof password === "function"
389
+ ? jvmBuilder.digestAuth(underlyingSessionTo(username), underlyingSessionTo(password))
390
+ : jvmBuilder.digestAuth(underlyingSessionTo(username), password)
391
+ : typeof password === "function"
392
+ ? jvmBuilder.digestAuth(username, underlyingSessionTo(password))
393
+ : jvmBuilder.digestAuth(username, password)
394
+ ),
395
+ disableUrlEncoding: (): T => wrap(jvmBuilder.disableUrlEncoding()),
396
+ proxy: (proxy: Proxy): T => wrap(jvmBuilder.proxy(proxy._underlying)),
397
+ signWithOAuth1: (
398
+ consumerKey: Expression<string>,
399
+ clientSharedSecret: Expression<string>,
400
+ token: Expression<string>,
401
+ tokenSecret: Expression<string>
402
+ ): T =>
403
+ wrap(
404
+ typeof consumerKey === "function" &&
405
+ typeof clientSharedSecret === "function" &&
406
+ typeof token === "function" &&
407
+ typeof tokenSecret === "function"
408
+ ? jvmBuilder.signWithOAuth1(
409
+ underlyingSessionTo(consumerKey),
410
+ underlyingSessionTo(clientSharedSecret),
411
+ underlyingSessionTo(token),
412
+ underlyingSessionTo(tokenSecret)
413
+ )
414
+ : jvmBuilder.signWithOAuth1(
415
+ consumerKey as string,
416
+ clientSharedSecret as string,
417
+ token as string,
418
+ tokenSecret as string
419
+ )
420
+ )
421
+ });
422
+
423
+ export interface RequestWithBodyActionBuilder<T> {
424
+ /**
425
+ * Define a request body
426
+ *
427
+ * @param body - the request body
428
+ * @returns a new HttpRequestActionBuilder instance
429
+ */
430
+ body(body: Body): T;
431
+
432
+ // TODO processRequestBody
433
+
434
+ /**
435
+ * Set a multipart body part
436
+ *
437
+ * @param part - the part
438
+ * @returns a new HttpRequestActionBuilder instance
439
+ */
440
+ bodyPart(part: BodyPart): T;
441
+
442
+ /**
443
+ * Set multiple multipart body parts
444
+ *
445
+ * @param parts - the parts
446
+ * @returns a new HttpRequestActionBuilder instance
447
+ */
448
+ bodyParts(...parts: BodyPart[]): T;
449
+
450
+ /**
451
+ * Set the content-type header for multipart body.
452
+ *
453
+ * @returns a new HttpRequestActionBuilder instance
454
+ */
455
+ asMultipartForm(): T;
456
+
457
+ /**
458
+ * Set the content-type header for form-urlencoding body.
459
+ *
460
+ * @returns a new HttpRequestActionBuilder instance
461
+ */
462
+ asFormUrlEncoded(): T;
463
+
464
+ /**
465
+ * Set an HTML form parameter
466
+ *
467
+ * @param key - the parameter key, expressed as a Gatling Expression Language String
468
+ * @param value - the parameter value, expressed as a Gatling Expression Language String
469
+ * @returns a new HttpRequestActionBuilder instance
470
+ */
471
+ formParam(key: string, value: string): T;
472
+
473
+ /**
474
+ * Set an HTML form parameter
475
+ *
476
+ * @param key - the parameter key, expressed as a Gatling Expression Language String
477
+ * @param value - the parameter static value
478
+ * @returns a new HttpRequestActionBuilder instance
479
+ */
480
+ formParam(key: string, value: any): T;
481
+
482
+ /**
483
+ * Set an HTML form parameter
484
+ *
485
+ * @param key - the parameter key, expressed as a Gatling Expression Language String
486
+ * @param value - the parameter value, expressed as a function
487
+ * @returns a new HttpRequestActionBuilder instance
488
+ */
489
+ formParam(key: string, value: (session: Session) => any): T;
490
+
491
+ /**
492
+ * Set an HTML form parameter
493
+ *
494
+ * @param key - the parameter key, expressed as a function
495
+ * @param value - the parameter value, expressed as a Gatling Expression Language String
496
+ * @returns a new HttpRequestActionBuilder instance
497
+ */
498
+ formParam(key: (session: Session) => string, value: string): T;
499
+
500
+ /**
501
+ * Set an HTML form parameter
502
+ *
503
+ * @param key - the parameter key, expressed as a function
504
+ * @param value - the parameter static value
505
+ * @returns a new HttpRequestActionBuilder instance
506
+ */
507
+ formParam(key: (session: Session) => string, value: any): T;
508
+
509
+ /**
510
+ * Set an HTML form parameter
511
+ *
512
+ * @param key - the parameter key, expressed as a function
513
+ * @param value - the parameter value, expressed as a function
514
+ * @returns a new HttpRequestActionBuilder instance
515
+ */
516
+ formParam(key: (session: Session) => string, value: (session: Session) => any): T;
517
+
518
+ /**
519
+ * Set an HTML form multivalued parameter
520
+ *
521
+ * @param key - the parameter key, expressed as a Gatling Expression Language String
522
+ * @param values - the parameter values, as a Gatling EL string
523
+ * @returns a new HttpRequestActionBuilder instance
524
+ */
525
+ multivaluedFormParam(key: string, values: string): T;
526
+
527
+ /**
528
+ * Set an HTML form multivalued parameter
529
+ *
530
+ * @param key - the parameter key, expressed as a Gatling Expression Language String
531
+ * @param values - the static parameter values
532
+ * @returns a new HttpRequestActionBuilder instance
533
+ */
534
+ multivaluedFormParam(key: string, values: any[]): T;
535
+
536
+ /**
537
+ * Set an HTML form multivalued parameter
538
+ *
539
+ * @param key - the parameter key, expressed as a Gatling Expression Language String
540
+ * @param values - the parameter values, expressed as a function
541
+ * @returns a new HttpRequestActionBuilder instance
542
+ */
543
+ multivaluedFormParam(key: string, values: (session: Session) => any[]): T;
544
+
545
+ // FIXME missing overload multivaluedFormParam(name: (session: Session) => string, value: string): T;
546
+
547
+ /**
548
+ * Set an HTML form multivalued parameter
549
+ *
550
+ * @param key - the parameter key, expressed as a function
551
+ * @param values - the static parameter values
552
+ * @returns a new HttpRequestActionBuilder instance
553
+ */
554
+ multivaluedFormParam(key: (session: Session) => string, values: any[]): T;
555
+
556
+ /**
557
+ * Set an HTML form multivalued parameter
558
+ *
559
+ * @param key - the parameter key, expressed as a function
560
+ * @param values - the parameter values, expressed as a function
561
+ * @returns a new HttpRequestActionBuilder instance
562
+ */
563
+ multivaluedFormParam(key: (session: Session) => string, values: (session: Session) => any[]): T;
564
+
565
+ /**
566
+ * Set multiple form parameters
567
+ *
568
+ * @param map - the static parameters
569
+ * @returns a new HttpRequestActionBuilder instance
570
+ */
571
+ formParamMap(map: Record<string, any>): T;
572
+
573
+ /**
574
+ * Set multiple form parameters
575
+ *
576
+ * @param map - the parameters, expressed as a function
577
+ * @returns a new HttpRequestActionBuilder instance
578
+ */
579
+ formParamMap(map: (session: Session) => Record<string, any>): T;
580
+
581
+ /**
582
+ * Set a form, typically captured from a form check
583
+ *
584
+ * @param form - the form inputs, expressed as a Gatling Expression Language String
585
+ * @returns a new HttpRequestActionBuilder instance
586
+ */
587
+ form(form: string): T;
588
+
589
+ /**
590
+ * Set a form, typically captured from a form check
591
+ *
592
+ * @param map - the form inputs, expressed as a function
593
+ * @returns a new HttpRequestActionBuilder instance
594
+ */
595
+ form(map: (session: Session) => Record<string, any>): T;
596
+
597
+ /**
598
+ * Set a form file upload
599
+ *
600
+ * @param name - the name of the file part, expressed as a Gatling Expression Language String
601
+ * @param filePath - the path of the file, either relative to the root of the classpath, or
602
+ * absolute, expressed as a Gatling Expression Language String
603
+ * @returns a new HttpRequestActionBuilder instance
604
+ */
605
+ formUpload(name: string, filePath: string): T;
606
+
607
+ /**
608
+ * Set a form file upload
609
+ *
610
+ * @param name - the name of the file part, expressed as a function
611
+ * @param filePath - the path of the file, either relative to the root of the classpath, or
612
+ * absolute, expressed as a Gatling Expression Language String
613
+ * @returns a new HttpRequestActionBuilder instance
614
+ */
615
+ formUpload(name: (session: Session) => string, filePath: string): T;
616
+
617
+ /**
618
+ * Set a form file upload
619
+ *
620
+ * @param name - the name of the file part, expressed as a Gatling Expression Language String
621
+ * @param filePath - the path of the file, either relative to the root of the classpath, or
622
+ * absolute, expressed as a function
623
+ * @returns a new HttpRequestActionBuilder instance
624
+ */
625
+ formUpload(name: string, filePath: (session: Session) => string): T;
626
+
627
+ /**
628
+ * Set a form file upload
629
+ *
630
+ * @param name - the name of the file part, expressed as a function
631
+ * @param filePath - the path of the file, either relative to the root of the classpath, or
632
+ * absolute, expressed as a function
633
+ * @returns a new HttpRequestActionBuilder instance
634
+ */
635
+ formUpload(name: (session: Session) => string, filePath: (session: Session) => string): T;
636
+
637
+ /**
638
+ * Set the content-type header for JSON
639
+ *
640
+ * @returns a new DSL instance
641
+ */
642
+ asJson(): T;
643
+
644
+ /**
645
+ * Set the content-type header for XML
646
+ *
647
+ * @returns a new DSL instance
648
+ */
649
+ asXml(): T;
650
+ }
651
+
652
+ const requestWithBodyActionBuilderImpl = <T>(
653
+ jvmBuilder: JvmHttpRequestActionBuilder,
654
+ wrap: (_underlying: JvmHttpRequestActionBuilder) => T
655
+ ): RequestWithBodyActionBuilder<T> => ({
656
+ body: (body: Body): T => wrap(jvmBuilder.body(body._underlying)),
657
+ bodyPart: (part: BodyPart): T => wrap(jvmBuilder.bodyPart(part._underlying)),
658
+ bodyParts: (...parts: BodyPart[]): T => wrap(jvmBuilder.bodyParts(parts.map((part) => part._underlying))),
659
+ asMultipartForm: (): T => wrap(jvmBuilder.asMultipartForm()),
660
+ asFormUrlEncoded: (): T => wrap(jvmBuilder.asFormUrlEncoded()),
661
+ formParam: (key: Expression<string>, value: string | Expression<any>): T => {
662
+ if (typeof key === "function") {
663
+ if (typeof value === "function") {
664
+ return wrap(jvmBuilder.formParam(underlyingSessionTo(key), underlyingSessionTo(value)));
665
+ } else if (typeof value === "string") {
666
+ // FIXME it shows the value:any overload?
667
+ return wrap(jvmBuilder.formParam(underlyingSessionTo(key), value));
668
+ } else {
669
+ // FIXME it shows the value:func overload?
670
+ return wrap(jvmBuilder.formParam(underlyingSessionTo(key), value));
671
+ }
672
+ } else {
673
+ if (typeof value === "function") {
674
+ // FIXME it shows the value:any overload?
675
+ return wrap(jvmBuilder.formParam(key, underlyingSessionTo(value)));
676
+ } else if (typeof value === "string") {
677
+ // FIXME it shows the value:any overload?
678
+ return wrap(jvmBuilder.formParam(key, value));
679
+ } else {
680
+ return wrap(jvmBuilder.formParam(key, value));
681
+ }
682
+ }
683
+ },
684
+ multivaluedFormParam: (key: Expression<string>, values: string | Expression<any[]>): T => {
685
+ if (typeof key === "function") {
686
+ if (typeof values === "function") {
687
+ return wrap(jvmBuilder.multivaluedFormParam(underlyingSessionTo(key), underlyingSessionToJava(values) as any));
688
+ } else if (typeof values === "string") {
689
+ throw Error(`multivaluedFormParam() called with invalid arguments ${key}, ${values}`);
690
+ } else {
691
+ return wrap(jvmBuilder.multivaluedFormParam(underlyingSessionTo(key), values));
692
+ }
693
+ } else {
694
+ if (typeof values === "function") {
695
+ return wrap(jvmBuilder.multivaluedFormParam(key, underlyingSessionToJava(values) as any));
696
+ } else if (typeof values === "string") {
697
+ return wrap(jvmBuilder.multivaluedFormParam(key, values));
698
+ } else {
699
+ return wrap(jvmBuilder.multivaluedFormParam(key, values));
700
+ }
701
+ }
702
+ },
703
+ formParamMap: (map: Expression<Record<string, any>>): T =>
704
+ wrap(
705
+ typeof map === "function"
706
+ ? (jvmBuilder as any)["formParamMap(java.util.function.Function)"](underlyingSessionToJava(map as any))
707
+ : jvmBuilder.formParamMap(map)
708
+ ),
709
+ form: (form: string | ((session: Session) => Record<string, any>)): T =>
710
+ wrap(typeof form === "function" ? jvmBuilder.form(underlyingSessionToJava(form) as any) : jvmBuilder.form(form)),
711
+ formUpload: (name: Expression<string>, filePath: Expression<string>): T =>
712
+ wrap(
713
+ typeof name === "function"
714
+ ? typeof filePath === "function"
715
+ ? jvmBuilder.formUpload(underlyingSessionTo(name), underlyingSessionTo(filePath))
716
+ : jvmBuilder.formUpload(underlyingSessionTo(name), filePath)
717
+ : typeof filePath === "function"
718
+ ? jvmBuilder.formUpload(name, underlyingSessionTo(filePath))
719
+ : jvmBuilder.formUpload(name, filePath)
720
+ ),
721
+ asJson: (): T => wrap(jvmBuilder.asJson()),
722
+ asXml: (): T => wrap(jvmBuilder.asXml())
723
+ });
724
+
725
+ export interface RequestActionBuilder<T> {
726
+ /**
727
+ * Apply some checks
728
+ *
729
+ * @param checks - the checks
730
+ * @returns a new HttpRequestActionBuilder instance
731
+ */
732
+ check(...checks: CheckBuilder[]): T;
733
+
734
+ /**
735
+ * Apply some checks if some condition holds true
736
+ *
737
+ * @param condition - the condition, expressed as a function
738
+ * @returns the next DSL step
739
+ */
740
+ checkIf(condition: string): Condition<T>;
741
+
742
+ /**
743
+ * Apply some checks if some condition holds true
744
+ *
745
+ * @param condition - the condition, expressed as a function
746
+ * @returns the next DSL step
747
+ */
748
+ checkIf(condition: (session: Session) => boolean): Condition<T>;
749
+
750
+ // TODO checkIf response
751
+
752
+ /**
753
+ * Have this request ignore the common checks defined on the HTTP protocol configuration
754
+ *
755
+ * @returns a new HttpRequestActionBuilder instance
756
+ */
757
+ ignoreProtocolChecks(): T;
758
+
759
+ /**
760
+ * Have this request ignore the common checks defined on the HTTP protocol configuration
761
+ *
762
+ * @returns a new HttpRequestActionBuilder instance
763
+ */
764
+ silent(): T;
765
+
766
+ /**
767
+ * Instruct the reporting engine to forcefully report stats about this request, ignoring HTTP
768
+ * protocol configuration
769
+ *
770
+ * @returns a new HttpRequestActionBuilder instance
771
+ */
772
+ notSilent(): T;
773
+
774
+ /**
775
+ * Disable automatic redirect following
776
+ *
777
+ * @returns a new HttpRequestActionBuilder instance
778
+ */
779
+ disableFollowRedirect(): T;
780
+
781
+ // TODO transformResponse(f: (response: Response, session: Session) => Response): T;
782
+
783
+ /**
784
+ * Set some resources to be fetched concurrently after the main request. Next action in the
785
+ * Scenario will be performed once all resources are fetched.
786
+ *
787
+ * @param res - the resources
788
+ * @returns a new HttpRequestActionBuilder instance
789
+ */
790
+ resources(...res: HttpRequestActionBuilder[]): T;
791
+
792
+ /**
793
+ * Override the default request timeout defined in gatling.conf
794
+ *
795
+ * @param timeout - timeout the timeout
796
+ * @returns a new HttpRequestActionBuilder instance
797
+ */
798
+ requestTimeout(timeout: Duration): T;
799
+ }
800
+
801
+ const requestActionBuilderImpl = <T>(
802
+ jvmBuilder: JvmHttpRequestActionBuilder,
803
+ wrap: (_underlying: JvmHttpRequestActionBuilder) => T
804
+ ): RequestActionBuilder<T> => ({
805
+ check: (...checks: CheckBuilder[]): T => wrap(jvmBuilder.check(checks.map((c: CheckBuilder) => c._underlying))),
806
+ checkIf: (condition: string | SessionTo<boolean>): Condition<T> =>
807
+ wrapCondition(
808
+ typeof condition === "string"
809
+ ? jvmBuilder.checkIf(condition)
810
+ : jvmBuilder.checkIf(underlyingSessionTo(condition)),
811
+ wrap
812
+ ),
813
+ ignoreProtocolChecks: (): T => wrap(jvmBuilder.ignoreProtocolChecks()),
814
+ silent: (): T => wrap(jvmBuilder.silent()),
815
+ notSilent: (): T => wrap(jvmBuilder.notSilent()),
816
+ disableFollowRedirect: (): T => wrap(jvmBuilder.disableFollowRedirect()),
817
+ // TODO transformResponse: (f: (response: Response, session: Session) => Response): T =>
818
+ // wrap(jvmBuilder.transformResponse(wrapBiCallback(underlyingResponseTransform(f))))
819
+ resources: (...res: HttpRequestActionBuilder[]): T =>
820
+ wrap(jvmBuilder.resources(res.map((r) => r._underlying as JvmHttpRequestActionBuilder))),
821
+ requestTimeout: (duration: Duration): T => wrap(jvmBuilder.requestTimeout(toJvmDuration(duration)))
822
+ });
823
+
824
+ export interface HttpRequestActionBuilder
825
+ extends RequestWithParamsActionBuilder<HttpRequestActionBuilder>,
826
+ RequestWithBodyActionBuilder<HttpRequestActionBuilder>,
827
+ RequestActionBuilder<HttpRequestActionBuilder>,
828
+ ActionBuilder {
829
+ // Assembling all original subtypes
830
+ _underlying: JvmHttpRequestActionBuilder;
831
+ }
832
+
833
+ export const wrapHttpRequestActionBuilder = (_underlying: JvmHttpRequestActionBuilder): HttpRequestActionBuilder => ({
834
+ _underlying,
835
+ ...requestWithParamsActionBuilderImpl(_underlying, wrapHttpRequestActionBuilder),
836
+ ...requestWithBodyActionBuilderImpl(_underlying, wrapHttpRequestActionBuilder),
837
+ ...requestActionBuilderImpl(_underlying, wrapHttpRequestActionBuilder)
838
+ });