Skip to content

Add HttpVersion parameter to Invoke-WebRequest cmdlet - #15853

Merged
Dongbo Wang (daxian-dbw) merged 20 commits into
PowerShell:masterfrom
hayhay27:add-http-version-parameter
Nov 2, 2021
Merged

Add HttpVersion parameter to Invoke-WebRequest cmdlet#15853
Dongbo Wang (daxian-dbw) merged 20 commits into
PowerShell:masterfrom
hayhay27:add-http-version-parameter

Conversation

@hayhay27

@hayhay27 Maksim Ivanyuk (hayhay27) commented Aug 1, 2021

Copy link
Copy Markdown
Contributor

PR Summary

Fix #12641

  • Add HttpVersionCompletionsAttribute with completions 1.0, 1.1, 2.0, 3.0
  • Handle input conversions from string, int and double to Version (generalize ArgumentToVersionTransformationAttribute from Set-StrictMode)
  • Enrich Verbose mesasge for request with http version and uri
  • Add pester tests for HttpVersion completions
  • Add xUnit tests for ArgumentToVersionTransformationAttribute

PR Context

This PR addressed to issue #12641
At the moment impossible make requests to network resources served only with HTTP/2 cause of default http version in HttpRequestMessage.Version=1.1

Changes in this PR allow to set http version during invocation Invoke-RestMethod or Invoke-WebRequest

This is my first PR to PowerShell. I have a couple of questions about tests. How and where to implement (at least point me right place please).

PR Checklist

@ghost

Deleted user (ghost) commented Aug 1, 2021

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for test, I think we have no need to do real HTTP requests with specified version since we utilize .Net Runtime features. I think it would enough if you did manual checks and shared results.
Nevertheless, we must verify that (1) the parameter accepts well-know values without throw, (2) transformation attribute works (it could be xUnit tests), (3) tab-completion works.

Comment thread src/Microsoft.PowerShell.Commands.Utility/resources/WebCmdletStrings.resx Outdated
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Aug 1, 2021
@hayhay27

Copy link
Copy Markdown
Contributor Author

As for test, I think we have no need to do real HTTP requests with specified version since we utilize .Net Runtime features. I think it would enough if you did manual checks and shared results.
Nevertheless, we must verify that (1) the parameter accepts well-know values without throw, (2) transformation attribute works (it could be xUnit tests), (3) tab-completion works.

  1. do you mean a pester test?
  2. done with xunit
  3. done with xunit

Comment thread test/xUnit/csharp/test_HttpVersionCompleter.cs Outdated
Comment thread test/xUnit/csharp/test_HttpVersionTransformationAttribute.cs Outdated
Comment thread test/xUnit/csharp/test_HttpVersionTransformationAttribute.cs Outdated
@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Aug 5, 2021
Comment thread src/Microsoft.PowerShell.Commands.Utility/resources/WebCmdletStrings.resx Outdated
@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Aug 19, 2021
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Aug 21, 2021
@hayhay27 Maksim Ivanyuk (hayhay27) changed the title WIP: Add HttpVersion parameter to Invoke-WebRequest cmdlet Add HttpVersion parameter to Invoke-WebRequest cmdlet Aug 21, 2021
Comment thread test/xUnit/csharp/test_ArgumentToVersionTransformationAttribute.cs Outdated
@hayhay27

Copy link
Copy Markdown
Contributor Author

I have no idea about failed tests )
What is that? )

@iSazonov

Copy link
Copy Markdown
Collaborator

Maksim Ivanyuk (@hayhay27) Please update the PR description to address latest code changes.

@hayhay27 Maksim Ivanyuk (hayhay27) left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PR description to address latest code changes.

done

Comment thread test/xUnit/csharp/test_ArgumentToVersionTransformationAttribute.cs Outdated
@hayhay27

Copy link
Copy Markdown
Contributor Author

while we keep silence

I thought with your blessing I can update docs for this PR

fixes by review
- remove HttpVersionUtils
- refactor pester test
@hayhay27

Copy link
Copy Markdown
Contributor Author

Rob Holt (@rjmholt) Thanks a lot!
I applied all your comments

@daxian-dbw

Copy link
Copy Markdown
Member

Rob Holt (@rjmholt) Can you please take another look?

Comment thread src/System.Management.Automation/engine/InternalCommands.cs Outdated
@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 2, 2021
fixes by review
- extend version transformation via method override instead of ctor injection
- clean up code
@pull-request-quantifier-deprecated

Copy link
Copy Markdown

This PR has 254 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Large
Size       : +186 -68
Percentile : 65.4%

Total files changed: 10

Change summary by file extension:
.cs : +145 -66
.resx : +2 -2
.ps1 : +39 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 2, 2021

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 674ef88 into PowerShell:master Nov 2, 2021
@daxian-dbw

Copy link
Copy Markdown
Member

Maksim Ivanyuk (@hayhay27) Thank you for your contribution!

@ghost

Copy link
Copy Markdown

🎉v7.3.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

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

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Large WG-Cmdlets general cmdlet issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

invoke-restmethod does not support http/2

5 participants