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.
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
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:
Reverting to this piece of code should work:
*edit after testing*: this is wrong. Simply returning
request
works for me instead (remove the whole condition onresponse
). 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/3393499Hello, 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
Thanks.