Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19950] iOS: HTTP requests with basic auth returning with 401 Unauthorised trigger endless repeated requests

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-01-14T02:55:08.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.1.2
ComponentsiOS
LabelsCommunity, httpclient, regression
ReporterTerry Morgan
AssigneeEric Merriman
Created2015-11-11T14:27:43.000+0000
Updated2017-03-21T20:44:27.000+0000

Description

Making an HTTP request with basic auth that that results in a 401 response causes the same request to be repeated resulting in an endless loop of HTTP requests. Neither onload nor onerror callback is called. Test case:
var url = "http://httpbin.org/basic-auth/user/passwd";
var client = Ti.Network.createHTTPClient({
    // function called when the response data is available
    onload : function(e) {
        Ti.API.info("Received text: " + this.responseText);
        alert('success');
    },
    // function called when an error occurs, including a timeout
    onerror : function(e) {
        Ti.API.debug(e.error);
        alert('error');
    },
    username: "test",
    password: "test",
    timeout : 5000  // in milliseconds
});
// Prepare the connection.
client.open("GET", url);
// Send the request.
client.send();

Comments

  1. Aminul Islam 2015-11-12

    Hi , I tested the issue you reported . I can reproduce it only iPhone devices but everything worked fine on simulators. I tested this using the 5.1.0.v20151021104424. This is a valid issue. *Environment*
       Thu Nov 12 2015 12:19:29 GMT+0600 (BDT)
       Operating System
         Name                        = Mac OS X
         Version                     = 10.10.5
         Architecture                = 64bit
         # CPUs                      = 4
         Memory                      = 8589934592
       Node.js
         Node.js Version             = 0.10.37
         npm Version                 = 1.4.28
       Titanium CLI
         CLI Version                 = 5.0.5
       Titanium SDK
         SDK Version                 = 5.1.0.v20151021104424
         SDK Path                    = /Users/Library/Application Support/Titanium/mobilesdk/osx/5.1.0.v20151021104424.
         Target Platform             = iphone
       
    Thanks
  2. Terry Morgan 2015-11-12

    I've tested this against 2 different APIs with the same result. If you're not familiar with it, http://httpbin.org is a very useful resource for testing for specific API responses and it is one of the two APIs I have tested this against (as per my test case above). This seems to be an issue specific to 401 responses so it's important you test against a real API that returns a valid "401 Unauthorized" response to reproduce this issue. I mention this as your test code appears to use a dummy url. You may have used a real API when you actually tested but I wanted to check that this was definitely the case. I also notice that you're not setting the username & password for HTTP basic auth correctly in your test case. As per the Ti does, the username & password need to be set on the XHR object before calling open(), as per my test case. http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient-property-username Finally, it's important to either monitor the requests from the API end or use a proxy to monitor traffic as there will be no output whatsoever in the Titanium logs. Would you mind either confirming that your tests complies with the above or trying again to reproduce following the above guidelines?
  3. Carlos Henrique Zinato 2015-11-12

    Same here! But only on real device (iPhone 5). Everything worked fine on simulators...that's super strange! iOS 9.1 SDK 5.0.2
  4. Chee Kiat Ng 2015-11-23

  5. Chee Kiat Ng 2015-11-23

  6. Chee Kiat Ng 2016-01-14

  7. Lee Morris 2017-03-21

    Closing ticket as fixed.

JSON Source