@@ -567,29 +567,11 @@ protected override void ProcessRecord()
567567 FillRequestStream ( request ) ;
568568 try
569569 {
570- long requestContentLength = request . Content is null ? 0 : request . Content . Headers . ContentLength . Value ;
571-
572- string reqVerboseMsg = string . Format (
573- CultureInfo . CurrentCulture ,
574- WebCmdletStrings . WebMethodInvocationVerboseMsg ,
575- request . Version ,
576- request . Method ,
577- requestContentLength ) ;
578-
579- WriteVerbose ( reqVerboseMsg ) ;
580570
581571 _maximumRedirection = WebSession . MaximumRedirection ;
582572
583573 using HttpResponseMessage response = GetResponse ( client , request , handleRedirect ) ;
584574
585- string contentType = ContentHelper . GetContentType ( response ) ;
586- long ? contentLength = response . Content . Headers . ContentLength ;
587- string respVerboseMsg = contentLength is null
588- ? string . Format ( CultureInfo . CurrentCulture , WebCmdletStrings . WebResponseNoSizeVerboseMsg , response . Version , contentType )
589- : string . Format ( CultureInfo . CurrentCulture , WebCmdletStrings . WebResponseVerboseMsg , response . Version , contentLength , contentType ) ;
590-
591- WriteVerbose ( respVerboseMsg ) ;
592-
593575 bool _isSuccess = response . IsSuccessStatusCode ;
594576
595577 // Check if the Resume range was not satisfiable because the file already completed downloading.
@@ -638,6 +620,8 @@ protected override void ProcessRecord()
638620 string detailMsg = string . Empty ;
639621 try
640622 {
623+ string contentType = ContentHelper . GetContentType ( response ) ;
624+ long ? contentLength = response . Content . Headers . ContentLength ;
641625 // We can't use ReadAsStringAsync because it doesn't have per read timeouts
642626 TimeSpan perReadTimeout = ConvertTimeoutSecondsToTimeSpan ( OperationTimeoutSeconds ) ;
643627 string characterSet = WebResponseHelper . GetCharacterSet ( response ) ;
@@ -1296,7 +1280,42 @@ internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestM
12961280 _cancelToken = new CancellationTokenSource ( ) ;
12971281 try
12981282 {
1283+ long requestContentLength = request . Content is null ? 0 : request . Content . Headers . ContentLength . Value ;
1284+
1285+ string reqVerboseMsg = string . Format (
1286+ CultureInfo . CurrentCulture ,
1287+ WebCmdletStrings . WebMethodInvocationVerboseMsg ,
1288+ request . Version ,
1289+ request . Method ,
1290+ requestContentLength ) ;
1291+
1292+ WriteVerbose ( reqVerboseMsg ) ;
1293+
1294+ string reqDebugMsg = string . Format (
1295+ CultureInfo . CurrentCulture ,
1296+ WebCmdletStrings . WebRequestDebugMsg ,
1297+ request . ToString ( )
1298+ ) ;
1299+
1300+ WriteDebug ( reqDebugMsg ) ;
1301+
12991302 response = client . SendAsync ( currentRequest , HttpCompletionOption . ResponseHeadersRead , _cancelToken . Token ) . GetAwaiter ( ) . GetResult ( ) ;
1303+
1304+ string contentType = ContentHelper . GetContentType ( response ) ;
1305+ long ? contentLength = response . Content . Headers . ContentLength ;
1306+ string respVerboseMsg = contentLength is null
1307+ ? string . Format ( CultureInfo . CurrentCulture , WebCmdletStrings . WebResponseNoSizeVerboseMsg , response . Version , contentType )
1308+ : string . Format ( CultureInfo . CurrentCulture , WebCmdletStrings . WebResponseVerboseMsg , response . Version , contentLength , contentType ) ;
1309+
1310+ WriteVerbose ( respVerboseMsg ) ;
1311+
1312+ string resDebugMsg = string . Format (
1313+ CultureInfo . CurrentCulture ,
1314+ WebCmdletStrings . WebResponseDebugMsg ,
1315+ response . ToString ( )
1316+ ) ;
1317+
1318+ WriteDebug ( resDebugMsg ) ;
13001319 }
13011320 catch ( TaskCanceledException ex )
13021321 {
@@ -1361,17 +1380,6 @@ internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestM
13611380 {
13621381 FillRequestStream ( requestWithoutRange ) ;
13631382
1364- long requestContentLength = requestWithoutRange . Content is null ? 0 : requestWithoutRange . Content . Headers . ContentLength . Value ;
1365-
1366- string reqVerboseMsg = string . Format (
1367- CultureInfo . CurrentCulture ,
1368- WebCmdletStrings . WebMethodInvocationVerboseMsg ,
1369- requestWithoutRange . Version ,
1370- requestWithoutRange . Method ,
1371- requestContentLength ) ;
1372-
1373- WriteVerbose ( reqVerboseMsg ) ;
1374-
13751383 response . Dispose ( ) ;
13761384 response = GetResponse ( client , requestWithoutRange , handleRedirect ) ;
13771385 }
0 commit comments