@@ -567,29 +567,10 @@ 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 ) ;
580-
581570 _maximumRedirection = WebSession . MaximumRedirection ;
582571
583572 using HttpResponseMessage response = GetResponse ( client , request , handleRedirect ) ;
584573
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-
593574 bool _isSuccess = response . IsSuccessStatusCode ;
594575
595576 // Check if the Resume range was not satisfiable because the file already completed downloading.
@@ -638,6 +619,9 @@ protected override void ProcessRecord()
638619 string detailMsg = string . Empty ;
639620 try
640621 {
622+ string contentType = ContentHelper . GetContentType ( response ) ;
623+ long ? contentLength = response . Content . Headers . ContentLength ;
624+
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,40 @@ 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+ WriteDebug ( reqDebugMsg ) ;
1300+
12991301 response = client . SendAsync ( currentRequest , HttpCompletionOption . ResponseHeadersRead , _cancelToken . Token ) . GetAwaiter ( ) . GetResult ( ) ;
1302+
1303+ string contentType = ContentHelper . GetContentType ( response ) ;
1304+ long ? contentLength = response . Content . Headers . ContentLength ;
1305+ string respVerboseMsg = contentLength is null
1306+ ? string . Format ( CultureInfo . CurrentCulture , WebCmdletStrings . WebResponseNoSizeVerboseMsg , response . Version , contentType )
1307+ : string . Format ( CultureInfo . CurrentCulture , WebCmdletStrings . WebResponseVerboseMsg , response . Version , contentLength , contentType ) ;
1308+
1309+ WriteVerbose ( respVerboseMsg ) ;
1310+
1311+ string resDebugMsg = string . Format (
1312+ CultureInfo . CurrentCulture ,
1313+ WebCmdletStrings . WebResponseDebugMsg ,
1314+ response . ToString ( ) ) ;
1315+
1316+ WriteDebug ( resDebugMsg ) ;
13001317 }
13011318 catch ( TaskCanceledException ex )
13021319 {
@@ -1361,17 +1378,6 @@ internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestM
13611378 {
13621379 FillRequestStream ( requestWithoutRange ) ;
13631380
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-
13751381 response . Dispose ( ) ;
13761382 response = GetResponse ( client , requestWithoutRange , handleRedirect ) ;
13771383 }
0 commit comments