PowerShell: Regression from 7.3.3: Verbose Invoke-WebRequest / Invoke-WebRequest output is missing the byte count
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Invoke-RestMethod -Method HEAD http://example.org -Verbose
Expected behavior
VERBOSE: HTTP/1.1 HEAD with 0-byte payload
VERBOSE: received 648-byte response of content type text/html
Actual behavior
VERBOSE: HTTP/1.1 HEAD with 0-byte payload
VERBOSE: received -byte response of content type text/html
Note the missing number before “-byte”.
Error details
No response
Environment data
PowerShell Core 7.4.0-preview.1
Visuals
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (8 by maintainers)
I found the origin of the problem, it’s a .NET bug Test:
http://example.com/ always responds with the same Content-Length (checked with MITM-Proxy), but it’s not reported with
$handler.AutomaticDecompression = "All"
Tested in PS 5 - 7.3.3 - 7.4preview1 - latest, the bug is always there
<html><body>The content-encoding of the website is GZip, it might be related
So it sounds like we should report it when available, right?
N/A (as @CarloToso suggested):
Available (as before):
For the N/A case, I wonder if it’s worth being explicit about not knowing the size; pro: people will know that the information is unavailable; con: they might be wondering why - but that could explained in the docs.
But reports above say that sometimes we get the length.
Now that we introduced handler.AutomaticDecompression = “All”, we will probably
neverrarely recieve a content-length header. We should just remove it and change the message to something like#VERBOSE: received response of content type text/html
When calling an async method you should be doing
AsyncMethod().GetAwaiter().GetResult()
. Doing just.Result
is problematic becauseSee https://github.com/PowerShell/PowerShell/issues/19141 for more details.