Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
limartin opened this issue Jan 24, 2018 · 4 comments · Fixed by #6018
Closed
Assignees
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-Fixed The issue is fixed. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Comments

@limartin
Copy link

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

@SteveL-MSFT SteveL-MSFT added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label Jan 24, 2018
@SteveL-MSFT SteveL-MSFT added this to the 6.1.0-Consider milestone Jan 24, 2018
@SteveL-MSFT SteveL-MSFT 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 Jan 24, 2018
@SteveL-MSFT
Copy link
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 @markekraus

@markekraus
Copy link
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

@markekraus markekraus added the Resolution-By Design The reported behavior is by design. label Jan 24, 2018
@markekraus markekraus removed the Resolution-By Design The reported behavior is by design. label Jan 24, 2018
@markekraus
Copy link
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.

@markekraus markekraus reopened this Jan 24, 2018
@markekraus markekraus added the Issue-Bug Issue has been identified as a bug in the product label Jan 24, 2018
@markekraus
Copy link
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
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-Fixed The issue is fixed. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants