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

Dio not properly following redirects and returning incorrect response bodies #793

Closed
1 task done
2x2xplz opened this issue May 20, 2020 · 7 comments
Closed
1 task done

Comments

@2x2xplz
Copy link

2x2xplz commented May 20, 2020

New Issue Checklist

  • I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name flutter
Platform Version
Dio Version 3.0.7
Android Studio / Xcode Version IntelliJ 2020.1
Repro rate all the time (100%)
Repro with our demo prj
Demo project link see below

Issue Description and Steps

I am using Dio in a Flutter app and as part of testing, I was using the examples at https://the-internet.herokuapp.com/

I've noticed that whether or not I use the correct credentials to log into https://the-internet.herokuapp.com/login, the Dio response data is the same. It doesn't appear to see the login results message, nor does it go to the "secure" page upon a successful login.

Postman returns the correct HTML response, you can also view it correctly in Chrome DevTools or simple View Source. However Dio is unable to get the correct response (the Dart http package also returns incorrect response bodies).

The POST to "authenticate" returns a 303 redirect to either the "login" page again or to a "secure" page if successful. Dio only goes back to the login page (even with correct credentials) and does not include the "invalid credentials" message from the page source. The site does not use AJAX or require an additional HTTP call to get the login status, so that's not the issue.

My full test is:

import 'package:dio/dio.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_test/flutter_test.dart';


void main() {

  test('dio test', () async {

  test('dio test', () async {

    Dio dio = Dio();
    Response responseGET = await dio.get("https://the-internet.herokuapp.com/login");
    // should redirect back to login page, with invalid credentials message
    Response responsePOSTfail = await dio.post("https://the-internet.herokuapp.com/authenticate",
                                      data: {"username": "tomsmith", "password": "badpassword"},
                                      options: Options(contentType:Headers.formUrlEncodedContentType ));
    // should redirect to secure page, with success message and different content
    Response responsePOSTsuccess = await dio.post("https://the-internet.herokuapp.com/authenticate",
                                      data: {"username": "tomsmith", "password": "SuperSecretPassword!"},
                                      options: Options(contentType:Headers.formUrlEncodedContentType ));

    http.Response responseHTTP = await http.post("https://the-internet.herokuapp.com/authenticate",
                                      body: {"username": "tomsmith", "password": "SuperSecretPassword!"});

    // all 3 tests fail. all the responses should be different but they are all the same
    // expect(responseGET.data.toString(), isNot(equals(responsePOSTfail.data.toString())));
    expect(responseGET.data.toString(), isNot(equals(responsePOSTsuccess.data.toString())));
    // expect(responseGET.data.toString(), isNot(equals(responseHTTP.body)));

  });

}

Thanks very much!

@stale
Copy link

stale bot commented Jun 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Jun 19, 2020
@2x2xplz
Copy link
Author

2x2xplz commented Jun 19, 2020

This is not stale, the issue remains and is unresolved. Thank you.

@stale stale bot removed the stale label Jun 19, 2020
@stale
Copy link

stale bot commented Jul 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Jul 19, 2020
@2x2xplz
Copy link
Author

2x2xplz commented Jul 19, 2020

Again, the issue is unresolved. Thank you.

@stale stale bot removed the stale label Jul 19, 2020
@stale
Copy link

stale bot commented Aug 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Aug 19, 2020
@stale stale bot closed this as completed Aug 27, 2020
@shinobu-uwu
Copy link

Any progress on this issue?

@dipak-pd
Copy link

Does it not support redirect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants