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