Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1074] iOS: HTTPClient redirect 303 with POST instead of GET

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionInvalid
Resolution Date2015-09-28T15:41:31.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsTCSupportTriage
ReporterPierre VAN DE VELDE
AssigneeShak Hossain
Created2014-10-06T09:35:32.000+0000
Updated2016-03-08T07:37:25.000+0000

Description

Problem description

From titanium 3.3.0, when sending a POST request that being redirected with http code 303, the redirection is followed using POST method instead of GET (POST/redirect/GET design pattern).

Test case

Run this sample code with 3.2.3.GA, then with 3.3.0.GA :
 var handler = function(e) { Titanium.API.info( e, http.responseText ); };
 var http = Ti.Network.createHTTPClient({
     onload: handler,
     onerror: handler,
     timeout: 1000
 });
 http.open('POST', 'http://jigsaw.w3.org/HTTP/300/Go_303');
 http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 http.send();

Expected results

Running Titanium *3.2.3*, output should be :
 {
     code = 0;
     source = "[object TiNetworkClient]";
     success = 1;
     type = load;
 }
 ... <title>Redirect test page</title> ...
 Your browser made it!
Running Titanium *3.3.0* or greater, output should be :
 {
     code = 405;
     error = "HTTP error";
     source = "[object TiNetworkHTTPClient]";
     success = 0;
     type = error;
 }
 Method POST not allowed on this resource.

Comments

  1. Pierre VAN DE VELDE 2014-10-06

    Thanks to Fokke's help, I've noticed that here: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiNetworkHTTPClientProxy.m#L237-L247 It uses APSHTTPClient module, could it be that here is where it is missing the POST/redirect/GET pattern ? https://github.com/appcelerator/APSHTTPClient/blob/20fb741880ea5c0f79a5446c5f7f73debccc73af/APSHTTPClient/APSHTTPRequest.m#L250-L256
  2. Pierre VAN DE VELDE 2014-10-26

    I think [~Fokke] was right pointing this location in the code, actually this issue comes from this commit: https://github.com/appcelerator/APSHTTPClient/commit/0d86619e42b128faa090ce0066f398bf757468f4 As far as I understand, it seems [~vduggal] overrided the native behaviour of NSURLConnection (which should redirect using GET) by creating a new request:
       if (response) {
       	NSMutableURLRequest *r = [self.request mutableCopy];
       	r.URL = request.URL;
       	return r;
       } else {
       	return request;
       }
       
    Reverting to this piece of code should work:
       if (response) {
       	self.request.URL = request.URL;
       	return self.request;
       
    *edit after testing*: this is wrong. Simply returning request works for me instead (remove the whole condition on response). Might not handle 307 though [~vduggal]: Do you agree ? I hope we can fix this ASAP since it prevents me from updating! +Sources:+ _Blog post about overriding NSURLConnection behaviour_: http://tewha.net/2012/05/handling-302303-redirects _NSURLConnection doc about handling redirection_: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/RequestChanges.html *There's an interesting discussion about this topic on stackoverflow*: http://stackoverflow.com/a/3393499
  3. Amimul Hossain 2015-08-31

    Hello, I have tested this With the latest SDK release. The issue seems to be resolved in the latest SDK. TESTING ENVIONMENT CLI version 4.1.2, Appcelerator SDK version 4.1.0.GA iOS Simulator 8.3 Observed Result
       [INFO] :   helloappli/1.0 (4.1.0.d57aa7d)
       [INFO] :   {
       [INFO] :       code = 501;
       [INFO] :       error = "HTTP error";
       [INFO] :       source = "[object TiNetworkHTTPClient]";
       [INFO] :       success = 0;
       [INFO] :       type = error;
       [INFO] :   } Method GET not implemented.
       
    Thanks.

JSON Source