New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FollowRedirects not working #2045
Comments
I don't have anything to say about it. RestSharp just sets the I added a simple test and it passes: [Fact]
public void Ensure_follow_redirect() {
var value = false;
var options = new RestClientOptions { FollowRedirects = true, ConfigureMessageHandler = Configure};
var _ = new RestClient(options);
value.Should().BeTrue();
HttpMessageHandler Configure(HttpMessageHandler handler) {
value = ((handler as HttpClientHandler)!).AllowAutoRedirect;
return handler;
}
} |
I also added another test. The test server endpoint: _app.MapGet("redirect", () => Results.Redirect("/success", false, true)); and the test: public class RedirectTests {
readonly RestClient _client;
public RedirectTests(TestServerFixture fixture, ITestOutputHelper output) {
var options = new RestClientOptions(fixture.Server.Url) {
FollowRedirects = true
};
_client = new RestClient(options);
}
[Fact]
public async Task Can_Perform_GET_Async_With_Redirect() {
const string val = "Works!";
var request = new RestRequest("redirect");
var response = await _client.ExecuteAsync<Response>(request);
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Data!.Message.Should().Be(val);
}
class Response {
public string? Message { get; set; }
}
} It works fine. The request URL in the response also shows the |
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. |
What's the value of the response |
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? |
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. |
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
|
I placed url encoded cookies |
Yeah, it is definitely related to the change in cookie handling. RestSharp stopped using 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. |
Ok, I think because we don't use |
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 |
Now I checked using my |
You can also just tell RestSharp to add cookie container to the handler: var options = new RestClientOptions(url) {
ConfigureMessageHandler = h => {
h.CookieContainer = container;
return h;
}
};
var client = new RestClient(options); |
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) Ugh... |
If 'FollowRedirects = true', the request completion code is 'StatusCode: Found', but 'StatusCode: OK' is expected. Changing 'FollowRedirects = false' does nothing.
Same code on version 108.0.3 works as expected.
The text was updated successfully, but these errors were encountered: