Description:
While verifying results from an XHR feature change, I noted that the user agent for iOS and Android were different. On Android, the user agent is null.
Here are examples of the user agent info for iOS and android:
Android
{ 'x-titanium-id': 'd67defe8-12dd-45ba-b8fd-1e915158ee1b', 'x-requested-with': 'XMLHttpRequest', 'user-agent': '', host: '172.16.83.53:8000', connection: 'Keep-Alive' }
iOS
{ host: '127.0.0.1:8000', 'x-titanium-id': '589be76d-ff3d-42ff-baca-07f1363aced0', 'accept-encoding': 'gzip', 'user-agent': 'Appcelerator Titanium/3.1.1.v20130522190722 (iPhone Simulator/6.0; iPhone OS; en_US;)', connection: 'close', 'x-requested-with': 'XMLHttpRequest' }
Steps to reproduce:
1) Download and run the attached ".js" file with "node testserver.js"
2) Install the following test code and run in simulator
3) Press the send request button
Test code
var win = Ti.UI.createWindow({
backgroundColor : 'white'
});
var url = "http://127.0.0.1:8000";
var button = Ti.UI.createButton({
title : 'Send request',
top : 280,
width : 240,
height : 100
});
win.add(button);
button.addEventListener('click', function() {
var client = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000
});
client.open("GET", url);
// client.setRequestHeader('X-Titanium-Id', null);
client.send();
});
win.open();
Result:
Android user agent is null
Expected Result:
iOS and Android have parity with regards to user agent
From discussion, the ACS-pem inserter tries to find 'android' from user_agent, user_agent.match(/android/i). So the user-agent string needs to at least have that.
Information that may be relevant: * NetworkModule.java, line 131, does a setProperty for "userAgent" of System.getProperties().getProperty("http.agent") + " Titanium/" + TiApplication.getInstance().getTiBuildVersion() * TitaniumModule.java, line 69, has a hardwired "getUserAgent" that builds the same string as NetworkModule.java * TiHTTPClient.java, line 874, has setRequestHeader("User-Agent", (String) proxy.getProperty("userAgent")) Note, however, that neither userAgent property of NetworkModule nor TitaniumModule is ever transferred to TiHTTPClient, nor to other areas. In fact, the only other place userAgent is mentioned is in conjunction with Ti.UI.webView.
PR pending https://github.com/appcelerator/titanium_mobile/pull/4336 - master https://github.com/appcelerator/titanium_mobile/pull/4337 - 3_!_X
On device: { 'x-titanium-id': '557fb1a9-5ee6-421f-831c-31574bf5386f', 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Appcelerator Titanium/3.1.1 (SAMSUNG-SGH-I777; Android API Level: 10; en-US;)', host: '172.16.1.170:5678', connection: 'Keep-Alive' } Can't get the emulator running. Get the error:
A little IP and port tweaking and this functions as expected on emulator, Device, and packaged on device. Examples: EMULATOR: { 'x-titanium-id': '557fb1a9-5ee6-421f-831c-31574bf5386f', 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Appcelerator Titanium/3.1.1 (google_sdk; Android API Level: 15; en-US;)', host: '172.16.1.170:5678', connection: 'Keep-Alive' } Device/packaged builds: Request Headers: { 'x-titanium-id': '557fb1a9-5ee6-421f-831c-31574bf5386f', 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Appcelerator Titanium/3.1.1 (SAMSUNG-SGH-I337; Android API Level: 17; en-US;)', host: '172.16.1.170:5678', connection: 'Keep-Alive' } Request Headers: { 'x-titanium-id': '557fb1a9-5ee6-421f-831c-31574bf5386f', 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Appcelerator Titanium/3.1.1 (SAMSUNG-SGH-I777; Android API Level: 10; en-US;)', host: '172.16.1.170:5678', connection: 'Keep-Alive' } Request Headers: { 'x-titanium-id': '557fb1a9-5ee6-421f-831c-31574bf5386f', 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Appcelerator Titanium/3.1.1 (SAMSUNG-SGH-I747; Android API Level: 15; en-US;)', host: '172.16.1.170:5678', connection: 'Keep-Alive' }