You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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(response.StatusCode)&&response.Headers.Location!=null){_cancelToken.Cancel();_cancelToken=null;// if explicit count was provided, reduce it for this redirection.if(WebSession.MaximumRedirection>0){WebSession.MaximumRedirection--;}// For selected redirects that used POST, GET must be used with the// redirected Location.// Since GET is the default; POST only occurs when -Method POST is used.if(Method==WebRequestMethod.Post&&IsRedirectToGet(response.StatusCode)){// See https://msdn.microsoft.com/library/system.net.httpstatuscode(v=vs.110).aspxMethod=WebRequestMethod.Get;}currentUri=newUri(request.RequestUri,response.Headers.Location);// Continue to handle redirectionusing(client=GetHttpClient(handleRedirect:true))using(HttpRequestMessageredirectRequest=GetRequest(currentUri)){response=GetResponse(client,redirectRequest,keepAuthorization);}}
I think lines 1380-1406 could be repurposed to follow HTTP redirects from HTTPS. Unfortunately I encountered some issues with the -MaximumRedirection flag.
Can someone test if those lines are actually never used?
Does someone know how to check how many redirects are resolved in line 1378?
Sample code that follows HTTPS->HTTP redirects but can't stop at -MaximumRedirection flag
if(WebSession.MaximumRedirection>0&&IsRedirectCode(response.StatusCode)&&response.Headers.Location!=null){_cancelToken.Cancel();_cancelToken=null;// if explicit count was provided, reduce it for this redirection.if(WebSession.MaximumRedirection>0){WebSession.MaximumRedirection--;}// For selected redirects that used POST, GET must be used with the// redirected Location.// Since GET is the default; POST only occurs when -Method POST is used.if(Method==WebRequestMethod.Post&&IsRedirectToGet(response.StatusCode)){// See https://msdn.microsoft.com/library/system.net.httpstatuscode(v=vs.110).aspxMethod=WebRequestMethod.Get;}currentUri=newUri(request.RequestUri,response.Headers.Location);// Continue to handle redirectionusing(client=GetHttpClient(handleRedirect:true))using(HttpRequestMessageredirectRequest=GetRequest(currentUri)){response=GetResponse(client,redirectRequest,keepAuthorization);}}
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
All the redirects are resolved in line 1378
Proposed technical implementation details (optional)
I think lines 1380-1406 could be repurposed to follow HTTP redirects from HTTPS. Unfortunately I encountered some issues with the
-MaximumRedirectionflag.Can someone test if those lines are actually never used?
Does someone know how to check how many redirects are resolved in line 1378?
Sample code that follows HTTPS->HTTP redirects but can't stop at
-MaximumRedirectionflag