Skip to content
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

Implement automatic redirects for requests regardless of the HttpClient #2214

Open
AlexV525 opened this issue May 15, 2024 · 0 comments
Open
Labels
s: feature This issue indicates a feature request

Comments

@AlexV525
Copy link
Member

AlexV525 commented May 15, 2024

Request Statement

As Dart doc stated:

  /// Automatic redirect will only happen for "GET" and "HEAD" requests
  /// and only for the status codes [HttpStatus.movedPermanently]
  /// (301), [HttpStatus.found] (302),
  /// [HttpStatus.movedTemporarily] (302, alias for
  /// [HttpStatus.found]), [HttpStatus.seeOther] (303),
  /// [HttpStatus.temporaryRedirect] (307) and
  /// [HttpStatus.permanentRedirect] (308). For
  /// [HttpStatus.seeOther] (303) automatic redirect will also happen
  /// for "POST" requests with the method changed to "GET" when
  /// following the redirect.

The redirections will only happen in these circumstances.

But it might be great if other requests could follow redirections too.

Solution Brainstorm

Pseudo implementation:

int redirectTimes = 0;
Response response = await request(redirectTimes);
while (reseponse.isRedirect && redirectTimes < options.maxRedirects) {
  redirectTimes++;
  response = await request(redirectTimes);
}
if (response.isRedirect) {
  throw StateError('Maximum redirects limit reached.');
}
return response;
@AlexV525 AlexV525 added the s: feature This issue indicates a feature request label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: feature This issue indicates a feature request
Projects
None yet
Development

No branches or pull requests

1 participant