[TIMOB-10350] Android: Uppercase HTTP in url causes failure
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-08-10T14:25:12.000+0000 |
Affected Version/s | Release 2.1.1 |
Fix Version/s | Sprint 2012-16 API, Release 2.1.2, Release 3.0.0 |
Components | Android |
Labels | api, module_xml, parity, qe-review, qe-testadded |
Reporter | Jeff English |
Assignee | Hieu Pham |
Created | 2012-08-08T12:16:08.000+0000 |
Updated | 2013-12-10T06:02:14.000+0000 |
Description
If the URL of an HTTP request contains uppercase "HTTP" or "HTTPS" as the scheme then the request will fail badly.
The error is reproducible with the following simple example code:
var xhr = Ti.Network.createHTTPClient({
onload: function () {
Ti.API.info("SUCCESS" + this.responseText);
},
onerror: function (evt) {
Ti.API.error("ERROR:" + this.responseText);
}
});
xhr.open('GET', "HTTP://www.appcelerator.com:80");
xhr.send({});
}
The attached log file shows the output of the send operation. Note that I have enabled DBG in the code as well as added code to output the response.
Line 20 in the log: You can see the 'GET' request with an uppercase "HTTP" in the url
Line 23 in the log: You can see the 1st side-effect of the bad parse result -- it can't locate the port string
Line 37 in the log: You can see what it thinks it needs to invoke
Line 66 in the log: The start of the responseText that is actually received -- it contains bogus javascript code
I believe that this is all caused by the code in TiHTTPClient.java not properly handling the uppercase HTTP scheme. Around line 768 in TiHTTPCLient.java is the following code:
// if the url is not prepended with either http or
// https, then default to http and prepend the protocol
// to the url
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://" + url;
}
The result is that if the scheme is uppercase then the resulting URL that gets processed is "http://HTTP://..." and this throws the whole process off.
According to the IETF (http://www.ietf.org/rfc/rfc1738.txt):
{quote}
For resiliency, programs
interpreting URLs should treat upper case letters as equivalent to
lower case in scheme names (e.g., allow "HTTP" as well as "http").
{quote}
Note that this works fine on iOS.
Workaround for anyone running into this problem. Prior to calling 'open' on the http client object, replace the uppercase scheme using something like the following code:
url = url.replace(/^HTTP:/,"http:");
url = url.replace(/^HTTPS:/,"https:");
Attachments
File | Date | Size |
---|---|---|
HTTP_error.log | 2012-08-08T12:16:08.000+0000 | 23217 |
PR https://github.com/appcelerator/titanium_mobile/pull/2708
Fixed on 2_1_X by https://github.com/appcelerator/titanium_mobile/pull/2732
Closing as fixed. Tested and verified on: Titanium Studio, build: 2.1.1.201208091713 Titanium SDK, build: 2.1.2.v20120815081613 Devices: Nexus 7 tab (4.1)
Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/5039