followRedirects property

  1. @override
bool get followRedirects
override

Whether to follow redirects automatically.

Set this property to false if this request should not automatically follow redirects. The default is true.

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.

All headers added to the request will be added to the redirection request(s) except when forwarding sensitive headers like "Authorization", "WWW-Authenticate", and "Cookie". Those headers will be skipped if following a redirect to a domain that is not a subdomain match or exact match of the initial domain. For example, a redirect from "foo.com" to either "foo.com" or "sub.foo.com" will forward the sensitive headers, but a redirect to "bar.com" will not.

Any body send with the request will not be part of the redirection request(s).

For precise control of redirect handling, set this property to false and make a separate HTTP request to process the redirect. For example:

final client = HttpClient();
var uri = Uri.parse("http://localhost/");
var request = await client.getUrl(uri);
request.followRedirects = false;
var response = await request.close();
while (response.isRedirect) {
  response.drain();
  final location = response.headers.value(HttpHeaders.locationHeader);
  if (location != null) {
    uri = uri.resolve(location);
    request = await client.getUrl(uri);
    // Set the body or headers as desired.
    request.followRedirects = false;
    response = await request.close();
  }
}
// Do something with the final response.

Implementation

@override
bool get followRedirects => _httpClientRequest.followRedirects;
  1. @override
set followRedirects (bool value)
override

Whether to follow redirects automatically.

Set this property to false if this request should not automatically follow redirects. The default is true.

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.

All headers added to the request will be added to the redirection request(s) except when forwarding sensitive headers like "Authorization", "WWW-Authenticate", and "Cookie". Those headers will be skipped if following a redirect to a domain that is not a subdomain match or exact match of the initial domain. For example, a redirect from "foo.com" to either "foo.com" or "sub.foo.com" will forward the sensitive headers, but a redirect to "bar.com" will not.

Any body send with the request will not be part of the redirection request(s).

For precise control of redirect handling, set this property to false and make a separate HTTP request to process the redirect. For example:

final client = HttpClient();
var uri = Uri.parse("http://localhost/");
var request = await client.getUrl(uri);
request.followRedirects = false;
var response = await request.close();
while (response.isRedirect) {
  response.drain();
  final location = response.headers.value(HttpHeaders.locationHeader);
  if (location != null) {
    uri = uri.resolve(location);
    request = await client.getUrl(uri);
    // Set the body or headers as desired.
    request.followRedirects = false;
    response = await request.close();
  }
}
// Do something with the final response.

Implementation

@override
set followRedirects(bool value) => _httpClientRequest.followRedirects = value;