Open sgrekhov opened 6 years ago
any success on this 6 months in @sgrekhov, @rmacnak-google ?
I'm trying to redirect, get response.statusCode=302, but I can't get the client to follow the redirect, send the POST, get the proper location page
@sgrekhov I think this issue is mistaken. isRedirect
is only true if the response is a redirect, but whenever followRedirects
is true, redirects are followed and you instead get the redirected response which is not a redirect unlike the original response. You should instead test that response.redirects
contains the redirects that you expected. Do you agree? If so, then the tests/co19_2/src/LibTest/io/HttpClientResponse/isRedirect_A01_t02.dart
test should be updated accordingly (should I file an issue in the co19 repository?).
I can also clarify the documentation for isRedirect
by saying it will never be true if followRedirects
is true.
@eturk1 You should send HTTP 303 See Other instead of HTTP 302 Found when redirecting POST requests. This is the logic for deciding whether to follow the redirect in the Dart SDK:
bool get isRedirect {
if (_httpRequest.method == "GET" || _httpRequest.method == "HEAD") {
return statusCode == HttpStatus.movedPermanently ||
statusCode == HttpStatus.found ||
statusCode == HttpStatus.seeOther ||
statusCode == HttpStatus.temporaryRedirect;
} else if (_httpRequest.method == "POST") {
return statusCode == HttpStatus.seeOther;
}
return false;
}
According to the HttpClientRequest.isRedirect this getter should return
true
if status code is one of the normal redirect codes. But the following code demonstrates that this property returnsfalse
anyway