Skip to content

Conversation

@CarloToso
Copy link
Contributor

@CarloToso CarloToso commented Nov 11, 2022

PR Summary

Add 308 to possible redirect codes
Small cleanup of a nested if

PR Context

PR Checklist

@iSazonov
Copy link
Collaborator

@CarloToso This change can be very sensitive. We need detailed description of the scenario(s) you are trying to fix.

@CarloToso
Copy link
Contributor Author

CarloToso commented Nov 11, 2022

The status codes 300,301,302,303,307,308 are redirect codes, and should have similar behaviour.
Before this PR when setting -MaximumRedirection 0 -SkipHttpErrorCheck in the WebCmdlets only 301 and 302 (HttpStatusCode.Moved, HttpStatusCode.MovedPermanently and HttpStatusCode.Found) threw this nonterminating error The maximum redirection count has been exceeded. To increase the number of redirections allowed, supply a higher value to the -MaximumRedirection parameter.
You can check it with this code
300,301,302,303,307,308 | ForEach-Object {Invoke-WebRequest http://mockbin.org/redirect/$($_)?to=https://mockbin.org/status/200 -MaximumRedirection 0 -SkipHttpErrorCheck}

@CarloToso
Copy link
Contributor Author

Another option could be completely removing this non terminating error. So we have the same behaviour for -MaximumRedirection >= 0

@iSazonov
Copy link
Collaborator

@CarloToso While I agree that 308 is redirect code and should be handled in some way I have a concern that the PR changes not one scenario but same ones.

Supporting the HTTP client is a difficult task. We usually compare the behavior with wget. If you can create tests that work the same way for both clients, that would be convincing for reviewers.

@CarloToso
Copy link
Contributor Author

CarloToso commented Nov 12, 2022

@iSazonov I wrote this small test to compare curl, wget and invoke-webrequest

for ($maxredirs = 0; $maxredirs -le 2; $maxredirs++)
{
	Write-Host "MaximumRedirection == $maxredirs" -BackgroundColor Red
	Write-Host "-------------------Invoke-WebRequest-------------------"
	300,301,302,303,307,308 | ForEach-Object {Invoke-WebRequest "http://mockbin.org/redirect/$($_)?to=https://mockbin.org/redirect/302?to=https://mockbin.org/status/200" -Method HEAD -MaximumRedirection $maxredirs -SkipHttpErrorCheck}
	Write-Host "-------------------curl-------------------"
	300,301,302,303,307,308 | ForEach-Object {$x = curl.exe -LI --no-progress-meter "http://mockbin.org/redirect/$($_)?to=https://mockbin.org/redirect/302?to=https://mockbin.org/status/200" --max-redirs $maxredirs; ($x -join"`n").split("`n`n")[-1]}
	Write-Host "-------------------wget-------------------"
	300,301,302,303,307,308 | ForEach-Object {$x = .\wget.exe http://mockbin.org/redirect/$($_)?to=https://mockbin.org/redirect/302?to=https://mockbin.org/status/200 --max-redirect $maxredirs --spider --server-response 2>&1; ($x[0..($x.length-2)] -join"`n").split("Spider mode enabled. Check if remote file exists.")[-1]}
}

flags explained

curl -> -I == HEAD, -L == follow redirect
wget -> --spider == HEAD

It looks like they have similar behaviours:

$maxredirs = 0
Iwr ->error on 301 and 302 maximum redirections exceded
curl and wget -> always error maximum redirections exceded

$maxredirs = 1
Iwr ->no error
curl and wget -> always error maximum redirections exceded

I wasn't able to parse the maximum redirections exceded error correctly in wget, to visualize it use:

.\wget.exe http://mockbin.org/redirect/303?to=https://mockbin.org/redirect/302?to=https://mockbin.org/status/200 --max-redirect 0 --spider --server-response

I propose we remove the non terminating error (lines 1600-1614) from the webcmdlets, because it only appears for 2 status codes, and only for -MaximumRedirection 0

Maybe it might be useful in some edge cases, if that is the case adding the other redirect codes would be the right thing to do

@iSazonov
Copy link
Collaborator

@iSazonov I wrote this small test to compare curl, wget and invoke-webrequest

Thanks for your investigations! Can you share outputs (or screenshots)? For 308 particularly.

@CarloToso
Copy link
Contributor Author

CarloToso commented Nov 12, 2022

Invoke-WebRequest ($maxredirs -> 0, 1, max)
iwr0
iwr1
iwr2

Curl ($maxredirs -> 0, 1, max)
curl0
curl1
curl2

Wget ($maxredirs -> 0, 1, max)
wget0
(different code to display the redirections exceeded error)
wget1
wget2

@CarloToso CarloToso changed the title Webcmdlets small fix and cleanup redirects Webcmdlets add 308 to redirect codes and small cleanup Nov 14, 2022
Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

LGTM.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 14, 2022
@ghost ghost added the Review - Needed The PR is being reviewed label Nov 21, 2022
@ghost
Copy link

ghost commented Nov 21, 2022

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@pull-request-quantifier-deprecated

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


Quantification details

Label      : Extra Small
Size       : +18 -26
Percentile : 17.6%

Total files changed: 1

Change summary by file extension:
.cs : +18 -26

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 detected.
  • 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.

@CarloToso
Copy link
Contributor Author

Is something blocking this PR?

@iSazonov
Copy link
Collaborator

Is something blocking this PR?

Waiting review from @PaulHigin.

@ghost ghost removed the Review - Needed The PR is being reviewed label Nov 22, 2022
Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

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

LGTM

@iSazonov iSazonov self-assigned this Nov 22, 2022
@iSazonov iSazonov merged commit 83d3b0e into PowerShell:master Nov 22, 2022
@CarloToso CarloToso deleted the Webcmdlets-small-fix-and-cleanup-redirects branch November 22, 2022 17:27
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 Extra Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants