Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Invoke-WebRequest removes the Content-Type header from WebResponseObject's #4467

Copy link
Copy link
@markekraus

Description

@markekraus
Issue body actions

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.0
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-AnsweredThe question is answered.The question is answered.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.