cfug / cfug/dio

Implement automatic redirects for requests regardless of the `HttpClient`

Open
#2,214 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

s: feature
Dominant language
Dart
Stars
12.8k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

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;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Dio's current Dart HTTP client redirect handling and the existing redirect options. Review how redirects are handled for request methods and define tests covering additional methods and the maximum redirect limit. Done means supported requests follow redirects consistently and exceeding the limit is reported.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.