@@ -20,7 +20,7 @@ public static class HttpSourceExtensions
2020 {
2121 private const int DefaultMaxTries = 3 ;
2222
23- internal static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions
23+ internal static readonly JsonSerializerOptions JsonSerializerOptions = new ( )
2424 {
2525 Converters =
2626 {
@@ -193,7 +193,7 @@ public static async Task<T> ProcessStreamWithRetryAsync<T>(
193193 nuGetLogger ,
194194 token ) ;
195195 }
196- catch ( Exception ex ) when ( ShouldRetryStreamException ( attempt , fetchedHeaders , token , ex ) )
196+ catch ( Exception ex ) when ( ShouldRetryStreamException ( attempt , fetchedHeaders , ex , token ) )
197197 {
198198 logger . LogTransientWarning ( ex , "On attempt {Attempt}, processing the stream response body failed. Trying again." , attempt ) ;
199199 }
@@ -227,14 +227,14 @@ public static async Task<T> ProcessResponseWithRetryAsync<T>(
227227 nuGetLogger ,
228228 token ) ;
229229 }
230- catch ( Exception ex ) when ( ShouldRetryStreamException ( attempt , fetchedHeaders , token , ex ) )
230+ catch ( Exception ex ) when ( ShouldRetryStreamException ( attempt , fetchedHeaders , ex , token ) )
231231 {
232232 logger . LogTransientWarning ( ex , "On attempt {Attempt}, processing the response body for {Url} failed. Trying again." , attempt , url ) ;
233233 }
234234 }
235235 }
236236
237- private static bool ShouldRetryStreamException ( int attempt , bool fetchedHeaders , CancellationToken token , Exception ex )
237+ private static bool ShouldRetryStreamException ( int attempt , bool fetchedHeaders , Exception ex , CancellationToken token )
238238 {
239239 return attempt < 3
240240 && fetchedHeaders
@@ -294,24 +294,22 @@ public static async Task<BlobMetadata> GetBlobMetadataAsync(
294294 async stream =>
295295 {
296296 var buffer = new byte [ 16 * 1024 ] ;
297- using ( var md5 = MD5 . Create ( ) )
297+ using var md5 = MD5 . Create ( ) ;
298+ int read ;
299+ do
298300 {
299- int read ;
300- do
301- {
302- read = await stream . ReadAsync ( buffer , 0 , buffer . Length ) ;
303- md5 . TransformBlock ( buffer , 0 , read , buffer , 0 ) ;
304- }
305- while ( read > 0 ) ;
301+ read = await stream . ReadAsync ( buffer ) ;
302+ md5 . TransformBlock ( buffer , 0 , read , buffer , 0 ) ;
303+ }
304+ while ( read > 0 ) ;
306305
307- md5 . TransformFinalBlock ( Array . Empty < byte > ( ) , 0 , 0 ) ;
308- var contentMD5 = md5 . Hash ! . ToLowerHex ( ) ;
306+ md5 . TransformFinalBlock ( Array . Empty < byte > ( ) , 0 , 0 ) ;
307+ var contentMD5 = md5 . Hash ! . ToLowerHex ( ) ;
309308
310- return new BlobMetadata (
311- exists : true ,
312- hasContentMD5Header : false ,
313- contentMD5 : contentMD5 ) ;
314- }
309+ return new BlobMetadata (
310+ exists : true ,
311+ hasContentMD5Header : false ,
312+ contentMD5 : contentMD5 ) ;
315313 } ,
316314 logger ,
317315 token ) ;
0 commit comments