Skip to content

Implement automatic redirects for requests regardless of the HttpClient #2214

Open
@AlexV525

Description

@AlexV525

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    s: featureThis issue indicates a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions