12
12
//
13
13
//===----------------------------------------------------------------------===//
14
14
15
+ import Baggage
15
16
import Foundation
16
17
import Logging
17
18
import NIO
@@ -225,115 +226,67 @@ public class HTTPClient {
225
226
///
226
227
/// - parameters:
227
228
/// - url: Remote URL.
229
+ /// - context: Metadata propagated for instrumentation.
228
230
/// - deadline: Point in time by which the request must complete.
229
- public func get( url: String , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
230
- return self . get ( url: url, deadline: deadline, logger: HTTPClient . loggingDisabled)
231
- }
232
-
233
- /// Execute `GET` request using specified URL.
234
- ///
235
- /// - parameters:
236
- /// - url: Remote URL.
237
- /// - deadline: Point in time by which the request must complete.
238
- /// - logger: The logger to use for this request.
239
- public func get( url: String , deadline: NIODeadline ? = nil , logger: Logger ) -> EventLoopFuture < Response > {
240
- return self . execute ( . GET, url: url, deadline: deadline, logger: logger)
241
- }
242
-
243
- /// Execute `POST` request using specified URL.
244
- ///
245
- /// - parameters:
246
- /// - url: Remote URL.
247
- /// - body: Request body.
248
- /// - deadline: Point in time by which the request must complete.
249
- public func post( url: String , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
250
- return self . post ( url: url, body: body, deadline: deadline, logger: HTTPClient . loggingDisabled)
231
+ public func get( url: String , context: BaggageContext , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
232
+ return self . execute ( . GET, url: url, context: context, deadline: deadline)
251
233
}
252
234
253
235
/// Execute `POST` request using specified URL.
254
236
///
255
237
/// - parameters:
256
238
/// - url: Remote URL.
239
+ /// - context: Metadata propagated for instrumentation.
257
240
/// - body: Request body.
258
241
/// - deadline: Point in time by which the request must complete.
259
- /// - logger: The logger to use for this request.
260
- public func post( url: String , body: Body ? = nil , deadline: NIODeadline ? = nil , logger: Logger ) -> EventLoopFuture < Response > {
261
- return self . execute ( . POST, url: url, body: body, deadline: deadline, logger: logger)
242
+ public func post( url: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
243
+ return self . execute ( . POST, url: url, context: context, body: body, deadline: deadline)
262
244
}
263
245
264
246
/// Execute `PATCH` request using specified URL.
265
247
///
266
248
/// - parameters:
267
249
/// - url: Remote URL.
250
+ /// - context: Metadata propagated for instrumentation.
268
251
/// - body: Request body.
269
252
/// - deadline: Point in time by which the request must complete.
270
- public func patch( url: String , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
271
- return self . patch ( url: url, body: body, deadline: deadline, logger: HTTPClient . loggingDisabled)
272
- }
273
-
274
- /// Execute `PATCH` request using specified URL.
275
- ///
276
- /// - parameters:
277
- /// - url: Remote URL.
278
- /// - body: Request body.
279
- /// - deadline: Point in time by which the request must complete.
280
- /// - logger: The logger to use for this request.
281
- public func patch( url: String , body: Body ? = nil , deadline: NIODeadline ? = nil , logger: Logger ) -> EventLoopFuture < Response > {
282
- return self . execute ( . PATCH, url: url, body: body, deadline: deadline, logger: logger)
253
+ public func patch( url: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
254
+ return self . execute ( . PATCH, url: url, context: context, body: body, deadline: deadline)
283
255
}
284
256
285
257
/// Execute `PUT` request using specified URL.
286
258
///
287
259
/// - parameters:
288
260
/// - url: Remote URL.
261
+ /// - context: Metadata propagated for instrumentation.
289
262
/// - body: Request body.
290
263
/// - deadline: Point in time by which the request must complete.
291
- public func put( url: String , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
292
- return self . put ( url: url, body: body, deadline: deadline, logger: HTTPClient . loggingDisabled)
293
- }
294
-
295
- /// Execute `PUT` request using specified URL.
296
- ///
297
- /// - parameters:
298
- /// - url: Remote URL.
299
- /// - body: Request body.
300
- /// - deadline: Point in time by which the request must complete.
301
- /// - logger: The logger to use for this request.
302
- public func put( url: String , body: Body ? = nil , deadline: NIODeadline ? = nil , logger: Logger ) -> EventLoopFuture < Response > {
303
- return self . execute ( . PUT, url: url, body: body, deadline: deadline, logger: logger)
264
+ public func put( url: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
265
+ return self . execute ( . PUT, url: url, context: context, body: body, deadline: deadline)
304
266
}
305
267
306
268
/// Execute `DELETE` request using specified URL.
307
269
///
308
270
/// - parameters:
309
271
/// - url: Remote URL.
272
+ /// - context: Metadata propagated for instrumentation.
310
273
/// - deadline: The time when the request must have been completed by.
311
- public func delete( url: String , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
312
- return self . delete ( url: url, deadline: deadline, logger: HTTPClient . loggingDisabled)
313
- }
314
-
315
- /// Execute `DELETE` request using specified URL.
316
- ///
317
- /// - parameters:
318
- /// - url: Remote URL.
319
- /// - deadline: The time when the request must have been completed by.
320
- /// - logger: The logger to use for this request.
321
- public func delete( url: String , deadline: NIODeadline ? = nil , logger: Logger ) -> EventLoopFuture < Response > {
322
- return self . execute ( . DELETE, url: url, deadline: deadline, logger: logger)
274
+ public func delete( url: String , context: BaggageContext , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
275
+ return self . execute ( . DELETE, url: url, context: context, deadline: deadline)
323
276
}
324
277
325
278
/// Execute arbitrary HTTP request using specified URL.
326
279
///
327
280
/// - parameters:
328
281
/// - method: Request method.
329
282
/// - url: Request url.
283
+ /// - context: Metadata propagated for instrumentation.
330
284
/// - body: Request body.
331
285
/// - deadline: Point in time by which the request must complete.
332
- /// - logger: The logger to use for this request.
333
- public func execute( _ method: HTTPMethod = . GET, url: String , body: Body ? = nil , deadline: NIODeadline ? = nil , logger: Logger ? = nil ) -> EventLoopFuture < Response > {
286
+ public func execute( _ method: HTTPMethod = . GET, url: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
334
287
do {
335
288
let request = try Request ( url: url, method: method, body: body)
336
- return self . execute ( request: request, deadline : deadline , logger : logger ?? HTTPClient . loggingDisabled )
289
+ return self . execute ( request: request, context : context , deadline : deadline )
337
290
} catch {
338
291
return self . eventLoopGroup. next ( ) . makeFailedFuture ( error)
339
292
}
@@ -345,16 +298,16 @@ public class HTTPClient {
345
298
/// - method: Request method.
346
299
/// - socketPath: The path to the unix domain socket to connect to.
347
300
/// - urlPath: The URL path and query that will be sent to the server.
301
+ /// - context: Metadata propagated for instrumentation.
348
302
/// - body: Request body.
349
303
/// - deadline: Point in time by which the request must complete.
350
- /// - logger: The logger to use for this request.
351
- public func execute( _ method: HTTPMethod = . GET, socketPath: String , urlPath: String , body: Body ? = nil , deadline: NIODeadline ? = nil , logger: Logger ? = nil ) -> EventLoopFuture < Response > {
304
+ public func execute( _ method: HTTPMethod = . GET, socketPath: String , urlPath: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
352
305
do {
353
306
guard let url = URL ( httpURLWithSocketPath: socketPath, uri: urlPath) else {
354
307
throw HTTPClientError . invalidURL
355
308
}
356
309
let request = try Request ( url: url, method: method, body: body)
357
- return self . execute ( request: request, deadline : deadline , logger : logger ?? HTTPClient . loggingDisabled )
310
+ return self . execute ( request: request, context : context , deadline : deadline )
358
311
} catch {
359
312
return self . eventLoopGroup. next ( ) . makeFailedFuture ( error)
360
313
}
@@ -366,16 +319,17 @@ public class HTTPClient {
366
319
/// - method: Request method.
367
320
/// - secureSocketPath: The path to the unix domain socket to connect to.
368
321
/// - urlPath: The URL path and query that will be sent to the server.
322
+ /// - context: Metadata propagated for instrumentation.
369
323
/// - body: Request body.
370
324
/// - deadline: Point in time by which the request must complete.
371
325
/// - logger: The logger to use for this request.
372
- public func execute( _ method: HTTPMethod = . GET, secureSocketPath: String , urlPath: String , body : Body ? = nil , deadline : NIODeadline ? = nil , logger : Logger ? = nil ) -> EventLoopFuture < Response > {
326
+ public func execute( _ method: HTTPMethod = . GET, secureSocketPath: String , urlPath: String , context : BaggageContext , body : Body ? = nil , deadline : NIODeadline ? = nil ) -> EventLoopFuture < Response > {
373
327
do {
374
328
guard let url = URL ( httpsURLWithSocketPath: secureSocketPath, uri: urlPath) else {
375
329
throw HTTPClientError . invalidURL
376
330
}
377
331
let request = try Request ( url: url, method: method, body: body)
378
- return self . execute ( request: request, deadline : deadline , logger : logger ?? HTTPClient . loggingDisabled )
332
+ return self . execute ( request: request, context : context , deadline : deadline )
379
333
} catch {
380
334
return self . eventLoopGroup. next ( ) . makeFailedFuture ( error)
381
335
}
@@ -385,74 +339,37 @@ public class HTTPClient {
385
339
///
386
340
/// - parameters:
387
341
/// - request: HTTP request to execute.
342
+ /// - context: Metadata propagated for instrumentation.
388
343
/// - deadline: Point in time by which the request must complete.
389
- public func execute( request: Request , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
390
- return self . execute ( request: request, deadline: deadline, logger: HTTPClient . loggingDisabled)
391
- }
392
-
393
- /// Execute arbitrary HTTP request using specified URL.
394
- ///
395
- /// - parameters:
396
- /// - request: HTTP request to execute.
397
- /// - deadline: Point in time by which the request must complete.
398
- /// - logger: The logger to use for this request.
399
- public func execute( request: Request , deadline: NIODeadline ? = nil , logger: Logger ) -> EventLoopFuture < Response > {
344
+ public func execute( request: Request , context: BaggageContext , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
400
345
let accumulator = ResponseAccumulator ( request: request)
401
- return self . execute ( request: request, delegate: accumulator, deadline : deadline , logger : logger ) . futureResult
346
+ return self . execute ( request: request, delegate: accumulator, context : context , deadline : deadline ) . futureResult
402
347
}
403
348
404
349
/// Execute arbitrary HTTP request using specified URL.
405
350
///
406
351
/// - parameters:
407
352
/// - request: HTTP request to execute.
408
353
/// - eventLoop: NIO Event Loop preference.
354
+ /// - context: Metadata propagated for instrumentation.
409
355
/// - deadline: Point in time by which the request must complete.
410
- public func execute( request: Request , eventLoop: EventLoopPreference , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
411
- return self . execute ( request: request,
412
- eventLoop: eventLoop,
413
- deadline: deadline,
414
- logger: HTTPClient . loggingDisabled)
415
- }
416
-
417
- /// Execute arbitrary HTTP request and handle response processing using provided delegate.
418
- ///
419
- /// - parameters:
420
- /// - request: HTTP request to execute.
421
- /// - eventLoop: NIO Event Loop preference.
422
- /// - deadline: Point in time by which the request must complete.
423
- /// - logger: The logger to use for this request.
424
- public func execute( request: Request ,
425
- eventLoop eventLoopPreference: EventLoopPreference ,
426
- deadline: NIODeadline ? = nil ,
427
- logger: Logger ? ) -> EventLoopFuture < Response > {
356
+ public func execute( request: Request , eventLoop: EventLoopPreference , context: BaggageContext , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
428
357
let accumulator = ResponseAccumulator ( request: request)
429
- return self . execute ( request: request, delegate: accumulator, eventLoop: eventLoopPreference , deadline : deadline , logger : logger ) . futureResult
358
+ return self . execute ( request: request, delegate: accumulator, eventLoop: eventLoop , context : context , deadline : deadline ) . futureResult
430
359
}
431
360
432
361
/// Execute arbitrary HTTP request and handle response processing using provided delegate.
433
362
///
434
363
/// - parameters:
435
364
/// - request: HTTP request to execute.
436
365
/// - delegate: Delegate to process response parts.
366
+ /// - context: Metadata propagated for instrumentation.
437
367
/// - deadline: Point in time by which the request must complete.
438
368
public func execute< Delegate: HTTPClientResponseDelegate > ( request: Request ,
439
369
delegate: Delegate ,
370
+ context: BaggageContext ,
440
371
deadline: NIODeadline ? = nil ) -> Task < Delegate . Response > {
441
- return self . execute ( request: request, delegate: delegate, deadline: deadline, logger: HTTPClient . loggingDisabled)
442
- }
443
-
444
- /// Execute arbitrary HTTP request and handle response processing using provided delegate.
445
- ///
446
- /// - parameters:
447
- /// - request: HTTP request to execute.
448
- /// - delegate: Delegate to process response parts.
449
- /// - deadline: Point in time by which the request must complete.
450
- /// - logger: The logger to use for this request.
451
- public func execute< Delegate: HTTPClientResponseDelegate > ( request: Request ,
452
- delegate: Delegate ,
453
- deadline: NIODeadline ? = nil ,
454
- logger: Logger ) -> Task < Delegate . Response > {
455
- return self . execute ( request: request, delegate: delegate, eventLoop: . indifferent, deadline: deadline, logger: logger)
372
+ return self . execute ( request: request, delegate: delegate, eventLoop: . indifferent, context: context, deadline: deadline)
456
373
}
457
374
458
375
/// Execute arbitrary HTTP request and handle response processing using provided delegate.
@@ -461,15 +378,18 @@ public class HTTPClient {
461
378
/// - request: HTTP request to execute.
462
379
/// - delegate: Delegate to process response parts.
463
380
/// - eventLoop: NIO Event Loop preference.
381
+ /// - context: Metadata propagated for instrumentation.
464
382
/// - deadline: Point in time by which the request must complete.
465
383
/// - logger: The logger to use for this request.
466
384
public func execute< Delegate: HTTPClientResponseDelegate > ( request: Request ,
467
385
delegate: Delegate ,
468
386
eventLoop eventLoopPreference: EventLoopPreference ,
387
+ context: BaggageContext ,
469
388
deadline: NIODeadline ? = nil ) -> Task < Delegate . Response > {
470
389
return self . execute ( request: request,
471
390
delegate: delegate,
472
391
eventLoop: eventLoopPreference,
392
+ context: context,
473
393
deadline: deadline,
474
394
logger: HTTPClient . loggingDisabled)
475
395
}
@@ -480,10 +400,12 @@ public class HTTPClient {
480
400
/// - request: HTTP request to execute.
481
401
/// - delegate: Delegate to process response parts.
482
402
/// - eventLoop: NIO Event Loop preference.
403
+ /// - context: Metadata propagated for instrumentation.
483
404
/// - deadline: Point in time by which the request must complete.
484
405
public func execute< Delegate: HTTPClientResponseDelegate > ( request: Request ,
485
406
delegate: Delegate ,
486
407
eventLoop eventLoopPreference: EventLoopPreference ,
408
+ context: BaggageContext ,
487
409
deadline: NIODeadline ? = nil ,
488
410
logger originalLogger: Logger ? ) -> Task < Delegate . Response > {
489
411
let logger = ( originalLogger ?? HTTPClient . loggingDisabled) . attachingRequestInformation ( request, requestID: globalRequestID. add ( 1 ) )
@@ -531,6 +453,7 @@ public class HTTPClient {
531
453
self . execute ( request: newRequest,
532
454
delegate: delegate,
533
455
eventLoop: eventLoopPreference,
456
+ context: context,
534
457
deadline: deadline)
535
458
}
536
459
case . disallow:
0 commit comments