Skip to content

WebCmdlets SetRequestContent wrong logic? #18973

@CarloToso

Description

@CarloToso

Prerequisites

Steps to reproduce

I was cleaning up the code of WebCmdlets #18964 and I noticed some code that seems incorrect. (WebRequestPSCmdlet.Common.cs lines 1114-1134)

if (content is FormObject form)
                {
                    SetRequestContent(request, form.Fields);
                }
                else if (content is IDictionary dictionary && request.Method != HttpMethod.Get)
                {
                    SetRequestContent(request, dictionary);
                }
                else if (content is XmlNode xmlNode)
                {
                    SetRequestContent(request, xmlNode);
                }
                else if (content is Stream stream)
                {
                    SetRequestContent(request, stream);
                }
                else if (content is byte[] bytes)
                {
                    SetRequestContent(request, bytes);
                }
                else if (content is MultipartFormDataContent multipartFormDataContent)

Expected behavior

`else if (content is IDictionary dictionary && request.Method != HttpMethod.Get)`

It seems this line doesn't set the request.Content if the method is GET and the body is a dictionary

Actual behavior

I think we should have a consistent behaviour for other type of bodys, for form and infile

Should we always set the request.Content, or never do it?

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions