Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17460] iOS: Ti.Network.createHTTPClient autoRedirect = false is ignored

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionCannot Reproduce
Resolution Date2014-10-21T16:18:42.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTiAPI
Labelsios
Reporterk
AssigneeMuhammad Dadu
Created2014-07-27T06:09:39.000+0000
Updated2017-03-21T22:08:34.000+0000

Description

Here is why and how it can be fixed. https://github.com/appcelerator/APSHTTPClient/pull/16 I debugged why autoRedirect property of Ti.Network.createHTTPClient is ignored for 3.3.0.GA. The default property of autoRedirect is true. When autoRedirect = false is set, self.response.status is always zero in APSHTTPRequest.m Therefore the redirect check if statement if (!self.redirects && self.response.status != 0) does always fall through. [self.response updateResponseParamaters:response]; needs to be called in advance

Comments

  1. Ingo Muschenetz 2014-08-14

    3.4.0 is moved forward, and 3.5.0 is taking its place in the calendar.
  2. Wilson Luu 2014-08-27

    One thing to note, I was not able to reproduce this issue on iOS. The autoRedirect property is respected: * If autoRedirect = true, then the target url will be auto-redirected and return status 200 * If autoRedirect = false, then the target url will not be auto-redirected and return status 302 *Tested on:* Appcelerator Studio, build: 3.3.0.201407111535 SDK build: 3.3.0.GA CLI: 3.3.0 Alloy: 1.4.1 Xcode: 5.1.1 Devices: iphone 5 (7.1.1) And, here is the app.js I used to verify this ticket:
       var win1 = Titanium.UI.createWindow({
             
       });
        
       // Create a Button.
       var aButton = Ti.UI.createButton({
           title : 'aButton',
       });
        
       // Listen for click events.
       aButton.addEventListener('click', function() {
        
           var url = "http://httpbin.org/redirect/2";
           var client = Ti.Network.createHTTPClient({
               // function called when the response data is available
               onload : function(e) {
                   Ti.API.info('e ' + JSON.stringify(e));
                   Ti.API.info('onload---------------------------------------------');
                   Ti.API.info("Received HEADERS_RECEIVED: " + this.HEADERS_RECEIVED);
                   Ti.API.info("Received status: " + this.status);
                   Ti.API.info("Received statusText: " + this.statusText);
                   Ti.API.info("Received responseText: " + this.responseText);
        
                   alert('success');
               },
               // function called when an error occurs, including a timeout
               onerror : function(e) {
                   Ti.API.debug(e.error);
                   Ti.API.info('onerror---------------------------------------------');
                   Ti.API.info("Received HEADERS_RECEIVED: " + this.HEADERS_RECEIVED);
                   Ti.API.info("Received status: " + this.status);
                   Ti.API.info("Received statusText: " + this.statusText);
                   Ti.API.info("Received responseText: " + this.responseText);
        
                   alert('error');
               },
               timeout : 5000,
               autoRedirect : false, // CHANGE ME
               autoEncodeUrl : false,
        
           });
           
           
           // Prepare the connection.
        
           client.open("GET", url);
           // Send the request.
           client.send();
        
       });
        
       // Add to the parent view.
       win1.add(aButton);
        
       win1.open();
       
  3. Ingo Muschenetz 2014-08-28

    [~kazuyukitanimura@gmail.com] Can you reproduce it with the code listed above?
  4. Jon Alter 2014-10-20

    Can't reproduce this issue. Tested using [~wluu]'s example code above.

    Environment

    TiSDK 3.4.0.GA iOS Sim 8.0 TiSDK 3.3.0.GA iPhone 5S iOS 8.0.2 [~kazuyukitanimura@gmail.com] please test using the example code above without your fix and let us know your results. Thank you!
  5. Vishal Duggal 2014-10-21

    Can not reproduce with sample code provided.
  6. Lee Morris 2017-03-21

    Closing ticket as the issue cannot be reproduced and due to the above comments.

JSON Source