Closed
Labels
awaiting-feedbackNeed feedback after the issue is fixed in previewNeed feedback after the issue is fixed in previewbug
Description
If 'FollowRedirects = true', the request completion code is 'StatusCode: Found', but 'StatusCode: OK' is expected. Changing 'FollowRedirects = false' does nothing.
var client = new RestClient(new RestClientOptions()
{
AutomaticDecompression = DecompressionMethods.All,
FollowRedirects = true,
MaxRedirects = 10,
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
BaseUrl = new Uri("https://steamcommunity.com/market/eligibilitycheck/?goto=%2Fmy%2Ftradeoffers%2Fprivacy"),
AllowMultipleDefaultParametersWithSameName = true,
Proxy = proxy,
RemoteCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; }
});
var container = new CookieContainer();
/*
* Add a steam cookie to container
*/
var request = new RestRequest(string.Empty, Method.Get) { CookieContainer = container };
request.AddHeader("Accept", "*/*");
request.AddHeader("DNT", "1");
request.AddHeader("Upgrade-Insecure-Requests", "1");
request.Timeout = 20000;
var response = await client.ExecuteAsync(req);
- OS: Windows 10 Pro 22H2 19045.2788
- .NET version 6
- Version 109 & 110
Same code on version 108.0.3 works as expected.
Metadata
Metadata
Assignees
Labels
awaiting-feedbackNeed feedback after the issue is fixed in previewNeed feedback after the issue is fixed in previewbug
Activity
alexeyzimarev commentedon Apr 4, 2023
I don't have anything to say about it. RestSharp just sets the
AllowAutoRedirectproperty ofHttpClientHandlerwith theFollowRedirectsvalue. It doesn't do anything further like responding toFoundand make consequent calls. It's very strange that it worked in 108 and stopped working in 109...I added a simple test and it passes:
alexeyzimarev commentedon Apr 4, 2023
I also added another test. The test server endpoint:
and the test:
It works fine. The request URL in the response also shows the
successendpoint instead ofredirect.rawensoft commentedon Apr 4, 2023
I don't know why this happens and I was surprised myself when I saw that in HttpClient 'AllowAutoRedirect: true', but it is not processed. I don't know how better to provide what I see than screenshots. I hope this somehow helps to solve the problem.
Details
Parameters of RestRequest

Parameters of RestResponse


Parameters of RestClient

Parameters of HttpClientHandler

alexeyzimarev commentedon Apr 4, 2023
What's the value of the response
Locationheader?rawensoft commentedon Apr 4, 2023
All headers in response

alexeyzimarev commentedon Apr 4, 2023
Weird. I searched for similar issues and only found out that https->http redirect don't work by design. What I can tell for sure is that nothing has changed with that code between v108 and v109 except using the read-only options in the client, but it doesn't affect anything as the option value is passed along correctly.
Are you absolutely sure that that's the only change? If you downgrade RestSharp to v108 right now without changing anything else, can you confirm it works as expected?
rawensoft commentedon Apr 4, 2023
i am absolutely sure. All I do to downgrade is move CookieContainer from RestClient to RestRequest, because there is no such option in the client. Now I checked it again on version 108.0.3 and it works correctly, but on version 109.0.0 it doesn't.
rawensoft commentedon Apr 4, 2023
Now I have checked the correct operation of the redirect through my site and it works as expected. Then I did a check through this link
https://steamcommunity.com/market/eligibilitycheck/?goto=%2Fmy%2Ftradeoffers%2Fprivacyand it works, but after I added my cookies, the redirect does not work anymore. Here is my test code for adding cookies that are responsible for authorization on the siterawensoft commentedon Apr 4, 2023
I placed url encoded cookies
sessionidandsteamLoginSecuredirect from browser and redirect not working.alexeyzimarev commentedon Apr 5, 2023
Yeah, it is definitely related to the change in cookie handling. RestSharp stopped using
CookieContainerin favour of settingSet-Cookieheaders. What's strange is that I added a test with a redirect endpoint and cookies and it also passes. Kind of hard to figure out the issue if I can't reproduce it...I looked if I can do manual redirect follow instead of relying on the handler. It seems to work, but it's a substantial change and I don't know if it solves your problem as I can't really reproduce it.
alexeyzimarev commentedon Apr 5, 2023
Ok, I think because we don't use
CookieContaineranymore, you get new cookies in the response and they aren't added to the follow up request. I still don't know why it doesn't follow the redirect, but it looks like the reason why things don't work.rawensoft commentedon Apr 5, 2023
I just realized this too. In the first request, the cookie must be received, and two more requests go along with the new cookie, but, since the cookie is not added, then they are redirected to the page for adding a cookie, and so it will be up to the
MaxRedirectsorTimeout.rawensoft commentedon Apr 5, 2023
Now I checked using my
HttpClientandHttpClientHandler, in which I addedCookieContainer, and everything works as before. Now I have no more questions.alexeyzimarev commentedon Apr 7, 2023
You can also just tell RestSharp to add cookie container to the handler:
rassilon commentedon Jul 19, 2023
Except, if I do that with 110.1.0, reponse.Cookies doesn't contain the expected cookies. Neither does the container supplied to HtpClientHandler.CookieContainer. RestSharpRequest.Cookies doesn't contain the correct data either (after execution, although any asp.net core anti-forgery cookies are there but nowhere else)
Neither does client.Options.CookieContainer. :(
Ugh...