Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17584] iOS: HTTPClient: AutoRedirect = false returns 200 status code, not 301/302

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-10-21T16:17:44.000+0000
Affected Version/sRelease 3.3.0
Fix Version/sRelease 3.4.2, Release 3.5.0, Release 4.0.0
ComponentsiOS
LabelsTCSupport, module_network, qe-manualtest
ReporterMatthew Delmarter
AssigneeIngo Muschenetz
Created2014-08-12T19:26:51.000+0000
Updated2018-11-13T12:03:35.000+0000

Description

Problem Description

When a GET request should be returning a status of "301" or "302", I have the 3.3.0 GA SDK returning a "200". Switching back to the 3.2.3 GA SDK fixes the problem. When we have tested using the following code, the status returned is "302" in 3.3.0.GA and "301" in 3.2.3.GA.

Steps to reproduce

a) Create a simple project. b) Update this code in app.js:
var xhr = Titanium.Network.createHTTPClient();
xhr.autoRedirect = false;
xhr.allResponseHeaders = true;

// what to do if it loads
xhr.onload = function(e) {

	Ti.API.log('Status = ' + this.getStatus());

	if (this.getStatus() == 301) {
		Ti.API.log('Redirect to ' + this.getResponseHeader('location'));
	} else {
		Ti.API.log('This should have returned a 301 not a 200');
	}
};

xhr.open('GET', 'http://google.co.nz');
xhr.send();
c) Run this with testing environment

Test results

In Titanium SDK: 3.3.0.GA [DEBUG]: Application booted in 125.191987 ms [INFO] : Status = 302 [INFO] : This should have returned a 301 not a 200 In Titanium SDK: 3.2.3.GA [DEBUG]: Application booted in 110.395968 ms [INFO] : Status = 301 [INFO] : Redirect to http://www.google.co.nz/

Attachments

FileDateSize
Redirectinfo.png2014-09-05T23:34:33.000+000012377

Comments

  1. Matthew Delmarter 2014-08-12

    Some sample code:
       var xhr = Titanium.Network.createHTTPClient();
       xhr.autoRedirect = false;
       xhr.allResponseHeaders = true;
        
       // what to do if it loads
       xhr.onload  = function (e) {
        
           Ti.API.log('Status = ' + this.getStatus());
        
           if (this.getStatus() == 301) {
               Ti.API.log('Redirect to ' + this.getResponseHeader('location'));
           } else {
               Ti.API.log('This should have returned a 301 not a 200');
           }
       };
        
       xhr.open('GET', 'http://google.co.nz');
       xhr.send();
       
    On OS X Yosemite, with Xcode 5.1.1, iOS Simulator 7.1, and SDK 3.3.0 this returns a response of "200". Incorrect. On OS X Yosemite, with Xcode 5.1.1, iOS Simulator 7.1, and SDK 3.2.3 this returns a response of "301". Correct. On my iPhone running iOS 8 beta 5 I can confirm that SDK 3.3.0 was also returning a "200", and switching back to 3.2.3 fixed the issue to return a "301" again.
  2. Matthew Delmarter 2014-08-12

    Possibly related to TIMOB-15871.
  3. icaiza 2014-08-12

    hello, I commented that I could give you a solution but not the right as it is impossible for me to handle the error. My url is for session start and redirects the browser along with a session cookie. var xhr = Ti.Network.createHTTPClient({timeout: 8000, autoRedirect: false}); // xhr.onreadystatechange = function() { if(this.readyState == 3){ var cookieArray = xhr.getResponseHeader("Set-Cookie"), //read cookie locationArray = xhr.getResponseHeader("Location") // read location redirect } //IF NULL cookiearray error or session no valid }; xhr.open("POST", "http://myurl.com/login"); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'); xhr.send({ "var1": "value1", "var2": "value2" }); By the way for iOs simply establish autoRedirect: false
  4. Pedro Enrique 2014-08-12

    [~mdelmarter] I'm looking at the source code and we're returning the status code that native implementation is giving us. https://github.com/appcelerator/APSHTTPClient/blob/master/APSHTTPClient/APSHTTPResponse.m#L25 I tested the URL you provided and it does return a redirect status code, 301. This is making the http client redirect to a different URL, http://www.google.co.nz/. If you still want to go to that URL, add the [autoRedirect](http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Network.HTTPClient-property-autoRedirect) property to the request to false
  5. Matthew Delmarter 2014-08-12

    Hi Pedro, Did you see my sample code above? autoRedirect is already set to false. As mentioned, running the exact code I submitted, and in the exact environments I submitted, the status returned is "200" in 3.3.0 and "301" in 3.2.3. I am not sure how else to describe the issue. Maybe it is Yosemite, or iOS 8 beta 5 that is key to seeing this issue? But my bug report is accurate for my build environment, and on my iPhone running iOS 8 beta 5.
  6. Pedro Enrique 2014-08-12

    You're right, my mistake. I just ran it with 3.3.0.GA and this is what I got.
       [DEBUG] Application booted in 164.345980 ms
       [INFO] Status = 302
       [INFO] This should have returned a 301 not a 200
       
    I'll give it another shot with iOS 8
  7. Pedro Enrique 2014-08-12

    Got the same thing with iOS 8 and Xcode 6-Beta 4
       [DEBUG] Application booted in 247.303009 ms
       [INFO] Status = 302
       [INFO] This should have returned a 301 not a 200
       
  8. Matthew Delmarter 2014-08-12

    Hi Pedro - it still intrigues me that you are getting a "302" instead of a "200" which I am getting on: * Yosemite + Xcode 5.5.1 + Simulator 7.1 + 3.3.0GA SDK. * Xcode 5.5.1 + iOS Beta 5 + 3.3.0GA SDK. Thanks for looking into it though.
  9. Matthew Delmarter 2014-09-01

    I think we can establish that this problem is not reproducible on OS X Version: 10.9.3. As mentioned in the initial bug report the problem was happening on Yosemite - which is OS X Version 10.10. And also on iOS 8 beta 5. Not iOS 7.1. All the tests I see here to reproduce and try and fix this issue are not using the platforms initially reported on? Maybe the issue is isolated to these environments. Can anybody clarify with a test on these platforms?
  10. Mauro Parra-Miranda 2014-09-01

    Hello [~mdelmarter]: In order to move this bug from TC to TIMOB, we need to provide a testcase. The testcase was tested on Ti Mobile SDK 3.3.0.GA, that's the reason it's being shown here. Best Regards
  11. Ingo Muschenetz 2014-09-02

    [~emerriman] To find duplicate.
  12. Ewan Harris 2014-09-05

    Ran the test code provided using the following environment: Mac OSX 10.9.4 Appcelerator Studio, build: 3.4.0.201409021758 Titanium SDK build: 3.4.0.v20140903121714, 3.3.0.GA, 3.2.3.GA Titanium CLI, build: 3.4.0-beta, 3.3.0 Alloy: 1.5.0-beta Xcode6-Beta7, Xcode5.1.1 iOS Devices iPhone 5(8.0b5), iPhone 5(7.1.1) As shown in the table below on both 3.4.0.v20140903121714 and 3.3.0.GA the status being shown is 200, this differs from 3.2.3.GA which gives us a 301. Using the Firefox webconsole to monitor this however I see that the website differs from all of these and gives a 302 status code followed by a 200 as shown in the attached screenshot || ||Status Code|| ||3.4.0.v20140903121714| 200 | ||3.3.0.GA| 200 | ||3.2.3.GA| 301 |
  13. Matthew Delmarter 2014-09-05

    @Ewan - I am so glad that somebody else has managed to confirm this issue.
  14. Matthew Delmarter 2014-09-19

    Really hoping to get a hot patch for this soon - I cannot update to SDK 3.3.0 or 3.4.0 without this fix, and with iOS 8 out the door it is getting more urgent.
  15. Matthew Delmarter 2014-09-19

    Out of curiosity is this bug fix/patch related? https://github.com/appcelerator/APSHTTPClient/pull/16
  16. Vishal Duggal 2014-10-21

    PR's merged APSHTTPClient - https://github.com/appcelerator/APSHTTPClient/pull/17 Titanium SDK master - https://github.com/appcelerator/titanium_mobile/pull/6230 3_4_X - https://github.com/appcelerator/titanium_mobile/pull/6245
  17. Matthew Delmarter 2014-10-21

    I can confirm that this fixes the issue. Thanks so much - you have no idea how happy it makes me to be able to use the 3.4.0 SDK in my app finally :)
  18. Ewan Harris 2014-11-25

    Verified fix on: Mac OSX 10.10.1 Appcelerator Studio, build: 3.4.1.201410281743 Titanium SDK build: 3.5.0.v20141124155715, Titanium CLI, build: 3.4.1 Alloy: 1.5.1 iPhone 6 Plus (8.1), iPhone 6 Simulator (8.2) Using the test case provided ran on simulator and device the status code returned is 301 as expected. Closing ticket.

JSON Source