@@ -198,15 +198,13 @@ public final class URLSessionHTTPClient: HTTPClient {
198
198
guard let tlsOptions = tlsOptions, tlsOptions. useSelfSignedCertificate,
199
199
let certFile = tlsOptions. certificate,
200
200
let serverTrust = challenge. protectionSpace. serverTrust else {
201
- logger. info (
202
- " Either TLSOptions not set or missing values! Using default trust store. "
203
- )
201
+ logger. debug ( " Either TLSOptions not set or missing values! Using default trust store. " )
204
202
completionHandler ( . performDefaultHandling, nil )
205
203
return
206
204
}
207
205
208
206
guard let customRoot = Bundle . main. certificate ( named: certFile) else {
209
- logger. info ( " Certificate not found! Using default trust store. " )
207
+ logger. debug ( " Certificate not found! Using default trust store. " )
210
208
completionHandler ( . performDefaultHandling, nil )
211
209
return
212
210
}
@@ -232,9 +230,7 @@ public final class URLSessionHTTPClient: HTTPClient {
232
230
guard let tlsOptions, tlsOptions. useProvidedKeystore,
233
231
let keystoreName = tlsOptions. pkcs12Path,
234
232
let keystorePasword = tlsOptions. pkcs12Password else {
235
- logger. info (
236
- " Either TLSOptions not set or missing values! Using default keystore. "
237
- )
233
+ logger. debug ( " Either TLSOptions not set or missing values! Using default keystore. " )
238
234
completionHandler ( . performDefaultHandling, nil )
239
235
return
240
236
}
@@ -275,8 +271,11 @@ public final class URLSessionHTTPClient: HTTPClient {
275
271
/// This callback is made as soon as the initial response + headers is complete.
276
272
/// Response body data may continue to stream in after this callback is received.
277
273
func urlSession(
278
- _ session: URLSession , dataTask: URLSessionDataTask , didReceive response: URLResponse
279
- ) async -> URLSession . ResponseDisposition {
274
+ _ session: URLSession ,
275
+ dataTask: URLSessionDataTask ,
276
+ didReceive response: URLResponse ,
277
+ completionHandler: @escaping ( URLSession . ResponseDisposition ) -> Void
278
+ ) {
280
279
logger. debug ( " urlSession(_:dataTask:didReceive response:) called " )
281
280
storage. modify ( dataTask) { connection in
282
281
guard let httpResponse = response as? HTTPURLResponse else {
@@ -295,7 +294,7 @@ public final class URLSessionHTTPClient: HTTPClient {
295
294
let response = HTTPResponse ( headers: headers, body: body, statusCode: statusCode)
296
295
connection. resume ( returning: response)
297
296
}
298
- return . allow
297
+ completionHandler ( . allow)
299
298
}
300
299
301
300
/// Called when the task needs a new `InputStream` to continue streaming the request body.
@@ -348,10 +347,12 @@ public final class URLSessionHTTPClient: HTTPClient {
348
347
/// If the error is returned prior to the initial response, the request fails with an error.
349
348
/// If the error is returned after the initial response, the error is used to fail the response stream.
350
349
func urlSession( _ session: URLSession , task: URLSessionTask , didCompleteWithError error: Error ? ) {
350
+ let httpMethod = task. originalRequest? . httpMethod ?? " "
351
+ let url = task. originalRequest? . url? . absoluteString ?? " "
351
352
if let error {
352
- logger. error ( " urlSession(_:task:didCompleteWithError:) failed. Error : \( error. localizedDescription ) " )
353
+ logger. error ( " URLRequest( \( httpMethod ) \( url ) ) failed with error : \( error) " )
353
354
} else {
354
- logger. debug ( " urlSession(_:task:didCompleteWithError:) called. Success " )
355
+ logger. debug ( " URLRequest( \( httpMethod ) \( url ) ) succeeded " )
355
356
}
356
357
357
358
// This connection is complete. No further data will be sent, and none will be received.
@@ -557,8 +558,10 @@ public final class URLSessionHTTPClient: HTTPClient {
557
558
delegate. storage. set ( connection, for: dataTask)
558
559
559
560
// Start the HTTP connection and start streaming the request body data, if needed
560
- logger. info ( " start URLRequest( \( urlRequest. url? . absoluteString ?? " " ) ) called " )
561
- logger. info ( " body is \( streamBridge != nil ? " InputStream " : " Data " ) " )
561
+ let httpMethod = urlRequest. httpMethod ?? " "
562
+ let url = urlRequest. url? . absoluteString ?? " "
563
+ logger. debug ( " URLRequest( \( httpMethod) \( url) ) started " )
564
+ logBodyDescription ( body)
562
565
dataTask. resume ( )
563
566
Task { [ streamBridge] in
564
567
await streamBridge? . open ( )
@@ -582,7 +585,7 @@ public final class URLSessionHTTPClient: HTTPClient {
582
585
/// Create a `URLRequest` for the Smithy operation to be performed.
583
586
/// - Parameters:
584
587
/// - request: The SDK-native, signed `HTTPRequest` ready to be transmitted.
585
- /// - httpBodyStream : A Foundation `InputStream` carrying the HTTP body for this request.
588
+ /// - body : A `Body` with either a stream bridge or data for this request's body .
586
589
/// - Returns: A `URLRequest` ready to be transmitted by `URLSession` for this operation.
587
590
private func makeURLRequest( from request: HTTPRequest , body: Body ) throws -> URLRequest {
588
591
var components = URLComponents ( )
@@ -592,7 +595,7 @@ public final class URLSessionHTTPClient: HTTPClient {
592
595
components. percentEncodedPath = request. destination. path
593
596
if let queryItems = request. queryItems, !queryItems. isEmpty {
594
597
components. percentEncodedQueryItems = queryItems. map {
595
- Foundation . URLQueryItem ( name: $0. name, value: $0. value)
598
+ URLQueryItem ( name: $0. name, value: $0. value)
596
599
}
597
600
}
598
601
guard let url = components. url else { throw URLSessionHTTPClientError . incompleteHTTPRequest }
@@ -622,6 +625,25 @@ public final class URLSessionHTTPClient: HTTPClient {
622
625
}
623
626
}
624
627
628
+ private func logBodyDescription( _ body: Body ) {
629
+ switch body {
630
+ case . stream( let stream) :
631
+ let lengthString : String
632
+ if let length = stream. readableStream. length {
633
+ lengthString = " \( length) bytes "
634
+ } else {
635
+ lengthString = " unknown length "
636
+ }
637
+ logger. debug ( " body is InputStream ( \( lengthString) ) " )
638
+ case . data( let data) :
639
+ if let data {
640
+ logger. debug ( " body is Data ( \( data. count) bytes) " )
641
+ } else {
642
+ logger. debug ( " body is empty " )
643
+ }
644
+ }
645
+ }
646
+
625
647
private static func makeServerAddress( sessionTask: URLSessionTask ) -> String {
626
648
let url = sessionTask. originalRequest? . url
627
649
let host = url? . host ?? " unknown "
0 commit comments