Skip to content

Inconsistent behavior from Invoke-RestMethod from Windows Powershell to Powershell Core #6002

Description

@limartin

Steps to reproduce

This same code, works in Powershell in Windows, where in Linux doesn't.

$contentType = "octet-stream"
$headers = @{"foo"="bar"}
Invoke-RestMethod -method post "http://foo/bar" -Headers $headers -ContentType $contentType -infile $chunkFile

Expected behavior


Actual behavior

The format of value 'octet-stream' is invalid. However, it does allows: "application/octect-stream"

Environment data

> $PSVersionTable
$PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0
PSEdition                      Core
GitCommitId                    v6.0.0
OS                             Linux 3.10.0-514.21.1.el7.x86_64 #1 SMP Thu May 25 17:04:51 UTC 2017
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. changed the title [-]Inconsistent behavior from Invoke-RestMethod from Powershell to Powershell in Linux[/-] [+]Inconsistent behavior from Invoke-RestMethod from Windows Powershell to Powershell Core[/+] on Jan 24, 2018
  2. SteveL-MSFT commented on Jan 24, 2018

    @SteveL-MSFT
    Member

    As far as I can tell, a mimetype consists of a type/subtype. Seems like we have 3 options here:

    • keep current behavior and just pass through which may be confusing to users transitioning from Windows PS to PS Core
    • error/warning if type is not specified
    • if no type specified, automatically prefix with "application/" (not sure how safe/dangerous it would be to do this)

    cc Mark Kraus (@markekraus)

  3. markekraus commented on Jan 24, 2018

    @markekraus
    Contributor

    Strict header validation is now default in PS core. This applies to any RFC defined header supplied to -Headers or -ContentType. One can bypass strict header validation with the -SkipHeaderValidation parameter.

    https://github.com/PowerShell/PowerShell/blob/master/docs/BREAKINGCHANGES.md#changes-to-web-cmdlets

    More info https://get-powershellblog.blogspot.com/2017/11/powershell-core-web-cmdlets-in-depth.html#L08

  4. markekraus commented on Jan 24, 2018

    @markekraus
    Contributor

    Actually... there seems to be some odd behavior here. -SkipHeaderValidation doesn't seem to work when -InFile is used. This is a bug. I'll have to look into it.

  5. markekraus commented on Jan 24, 2018

    @markekraus
    Contributor

    After investigating, -SkipHeaderValidation is not being applied at all to -ContentType. I should have a PR to fix this tomorrow or later today. I have the fix code, just need to write tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions