Title: Apparently unused code WebRequestPSCmdlet.Common.cs · Issue #18541 · PowerShell/PowerShell · GitHub
Open Graph Title: Apparently unused code WebRequestPSCmdlet.Common.cs · Issue #18541 · PowerShell/PowerShell
X Title: Apparently unused code WebRequestPSCmdlet.Common.cs · Issue #18541 · PowerShell/PowerShell
Description: Summary of the new feature / enhancement I was working on the WebCmdlets trying to understand how to fix issue #2896 and it seems that lines 1380-1406 in WebRequestPSCmdlet.Common.cs are never used if (keepAuthorization && IsRedirectCode...
Open Graph Description: Summary of the new feature / enhancement I was working on the WebCmdlets trying to understand how to fix issue #2896 and it seems that lines 1380-1406 in WebRequestPSCmdlet.Common.cs are never used...
X Description: Summary of the new feature / enhancement I was working on the WebCmdlets trying to understand how to fix issue #2896 and it seems that lines 1380-1406 in WebRequestPSCmdlet.Common.cs are never used...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/18541
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Apparently unused code WebRequestPSCmdlet.Common.cs","articleBody":"### Summary of the new feature / enhancement\r\n\r\nI was working on the WebCmdlets trying to understand how to fix issue #2896 and it seems that lines 1380-1406 in WebRequestPSCmdlet.Common.cs are never used\r\n\r\n```cs\r\n if (keepAuthorization \u0026\u0026 IsRedirectCode(response.StatusCode) \u0026\u0026 response.Headers.Location != null)\r\n {\r\n _cancelToken.Cancel();\r\n _cancelToken = null;\r\n\r\n // if explicit count was provided, reduce it for this redirection.\r\n if (WebSession.MaximumRedirection \u003e 0)\r\n {\r\n WebSession.MaximumRedirection--;\r\n }\r\n // For selected redirects that used POST, GET must be used with the\r\n // redirected Location.\r\n // Since GET is the default; POST only occurs when -Method POST is used.\r\n if (Method == WebRequestMethod.Post \u0026\u0026 IsRedirectToGet(response.StatusCode))\r\n {\r\n // See https://msdn.microsoft.com/library/system.net.httpstatuscode(v=vs.110).aspx\r\n Method = WebRequestMethod.Get;\r\n }\r\n\r\n currentUri = new Uri(request.RequestUri, response.Headers.Location);\r\n // Continue to handle redirection\r\n using (client = GetHttpClient(handleRedirect: true))\r\n using (HttpRequestMessage redirectRequest = GetRequest(currentUri))\r\n {\r\n response = GetResponse(client, redirectRequest, keepAuthorization);\r\n }\r\n }\r\n```\r\n\r\nAll the redirects are resolved in line 1378\r\n\r\n``` cs\r\nresponse = client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, _cancelToken.Token).GetAwaiter().GetResult();\r\n```\r\n\r\n### Proposed technical implementation details (optional)\r\n\r\nI think lines 1380-1406 could be repurposed to follow HTTP redirects from HTTPS. Unfortunately I encountered some issues with the `-MaximumRedirection` flag. \r\nCan someone test if those lines are actually never used?\r\nDoes someone know how to check how many redirects are resolved in line 1378?\r\n\r\nSample code that follows HTTPS-\u003eHTTP redirects but can't stop at `-MaximumRedirection` flag\r\n```cs\r\n if (WebSession.MaximumRedirection \u003e 0 \u0026\u0026 IsRedirectCode(response.StatusCode) \u0026\u0026 response.Headers.Location != null)\r\n {\r\n _cancelToken.Cancel();\r\n _cancelToken = null;\r\n\r\n // if explicit count was provided, reduce it for this redirection.\r\n if (WebSession.MaximumRedirection \u003e 0)\r\n {\r\n WebSession.MaximumRedirection--;\r\n }\r\n // For selected redirects that used POST, GET must be used with the\r\n // redirected Location.\r\n // Since GET is the default; POST only occurs when -Method POST is used.\r\n if (Method == WebRequestMethod.Post \u0026\u0026 IsRedirectToGet(response.StatusCode))\r\n {\r\n // See https://msdn.microsoft.com/library/system.net.httpstatuscode(v=vs.110).aspx\r\n Method = WebRequestMethod.Get;\r\n }\r\n\r\n currentUri = new Uri(request.RequestUri, response.Headers.Location);\r\n // Continue to handle redirection\r\n using (client = GetHttpClient(handleRedirect: true))\r\n using (HttpRequestMessage redirectRequest = GetRequest(currentUri))\r\n {\r\n response = GetResponse(client, redirectRequest, keepAuthorization);\r\n }\r\n }\r\n```","author":{"url":"https://github.com/CarloToso","@type":"Person","name":"CarloToso"},"datePublished":"2022-11-12T03:32:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/18541/PowerShell/issues/18541"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:19184b97-b248-dccc-1d24-7cdf43da1f67 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3DE:348621:166F6C0:1E6B17C:6A546419 |
| html-safe-nonce | c4e48aaf7949290fa5d7efedeed154c693b62b0637453bbf87ff844fad0ec35a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0RFOjM0ODYyMToxNjZGNkMwOjFFNkIxN0M6NkE1NDY0MTkiLCJ2aXNpdG9yX2lkIjoiOTY1MzkxNjM3ODM1NzAzMzIxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a64876e606b9dcb9dae1939fce0b27c01bc30b24731602c6bc95108da4b26231 |
| hovercard-subject-tag | issue:1446216829 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/18541/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d78916a0102b63464cb4854639c185fdf0b12f9308ff368a2b95d31cf947a0ed/PowerShell/PowerShell/issues/18541 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d78916a0102b63464cb4854639c185fdf0b12f9308ff368a2b95d31cf947a0ed/PowerShell/PowerShell/issues/18541 |
| og:image:alt | Summary of the new feature / enhancement I was working on the WebCmdlets trying to understand how to fix issue #2896 and it seems that lines 1380-1406 in WebRequestPSCmdlet.Common.cs are never used... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CarloToso |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6d28624802c2f7d9500239dd6870ed7031b7353b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width