Repository navigation
Closed
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueResolution-AnsweredThe question is answered.The question is answered.WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues
Description
The Content-Type header appears to be missing everywhere except $response.BaseResponse.Content.Headers.ContentType. it is even being removed from $response.RawContent . it happens regardless of using -UseBasicParsing or not, regardless of -method and regardless of -UserAgent.
Steps to reproduce
Describe 'Invoke-WebRequest' {
Context 'Response: Content-Type Header' {
$Uri = 'http://httpbin.org/headers'
$response = Invoke-WebRequest -Uri $Uri
It "Has BaseResponse.Content.Headers.ContentType" {
$response.BaseResponse.Content.Headers.ContentType |
Should Not BeNullOrEmpty
}
It "Has Headers.'Content-Type'" {
$response.Headers.ContainsKey('Content-Type') | Should Be $True
$response.Headers.'Content-Type' | Should Not BeNullOrEmpty
}
It "Has BaseResponse.Headers.'Content-Type'" {
$response.BaseResponse.Headers.Keys -contains 'Content-Type' | Should Be $True
$response.BaseResponse.Headers.Get('Content-Type') | Should Not BeNullOrEmpty
}
It "Has BaseResponse.ContentType" {
$response.BaseResponse.ContentType | Should Not BeNullOrEmpty
}
It "Has Content-Type in the RawContent" {
$response.RawContent -match 'Content-Type' | Should Be $True
}
}
}Expected behavior
Describing Invoke-WebRequest
Context Response: Content-Type Header
[+] Has BaseResponse.Content.Headers.ContentType.MediaType 12.62s
[+] Has Headers.'Content-Type' 11.36s
[+] Has BaseResponse.Headers.'Content-Type' 28ms
[+] Has BaseResponse.ContentType 10ms
[+] Has Content-Type in the RawContent 18ms
Actual behavior
Describing Invoke-WebRequest
Context Response: Content-Type Header
[+] Has BaseResponse.Content.Headers.ContentType 13.59s
[-] Has Headers.'Content-Type' 42ms
Expected: {True}
But was: {False}
at line: 10 in
10: $response.Headers.ContainsKey('Content-Type') | Should Be $True
[-] Has BaseResponse.Headers.'Content-Type' 23ms
Expected: {True}
But was: {False}
at line: 14 in
14: $response.BaseResponse.Headers.Keys -contains 'Content-Type' | Should Be $True
[-] Has BaseResponse.ContentType 24ms
Expected: value to not be empty
at line: 18 in
18: $response.BaseResponse.ContentType | Should Not BeNullOrEmpty
[-] Has Content-Type in the RawContent 28ms
Expected: {True}
But was: {False}
at line: 21 in
21: $response.RawContent -match 'Content-Type' | Should Be $True
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.4
OS Microsoft Windows 10.0.15063
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Metadata
Metadata
Assignees
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueResolution-AnsweredThe question is answered.The question is answered.WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues
Activity
SteveL-MSFT commentedon Aug 3, 2017
Compared to Windows PowerShell 5.1 it seems that
Content-Lengthis also missingSteveL-MSFT commentedon Aug 3, 2017
Looks like this is
by designofHttpResponseMessage(you'll have to open an issue with corefx if you want it changed). You can still get them, but they are in a different part of the object:As you can see, the
Headersproperty of the output object just mirrors.BaseResponse.Headersmarkekraus commentedon Aug 3, 2017
The new location on the objects is somewhat understandable, but, what about it being missing from
RawResponseonMicrosoft.PowerShell.Commands.BasicHtmlWebResponseObject?5.1:
6:
One would expect the
RawContentto truly be a "Raw Content". Is this also related to the CoreFX change? Is it something that should be worked around in PowerShell 6? Or should the expectation change thatContet-TypeandContent-Lengthwill not be available inRawContent?SteveL-MSFT commentedon Aug 3, 2017
The big difference between 6 and 5.1 is that 5.1 uses the WebResponse class while 6 uses the HttpResponseMessage class due to differences between CoreFx and .Net. In the case of
RawContent, it's just a "manual" serialization of HttpResponseMessage where those headers are not present. If coreFx put it "back", they would just show up with this cmdlet.We could add some specialized code to just add them, but it seems the correct change is in corefx.
markekraus commentedon Aug 3, 2017
Digging around the CoreFX source for
System.Net.Http.HttpResponseMessage, It appears the separation of the content headers is very much deliberate. TheToString()override is callingHeaderUtilities.DumpHeaders()and passing both_headersand_content. I don't think there is any chance of that being reversed.I'll do a PR for replicating that functionality in
ContentHelper