Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14012] Android: Parity - XHR user agent is null on Android, populated on iOS

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-05-29T18:43:51.000+0000
Affected Version/sRelease 3.1.1
Fix Version/s2013 Sprint 11 API, 2013 Sprint 11, Release 3.1.1, Release 3.2.0
ComponentsAndroid
Labelsqe-3.1.1, qe-testadded
ReporterEric Merriman
AssigneeSabil Rahim
Created2013-05-28T22:28:26.000+0000
Updated2015-09-13T07:08:30.000+0000

Description

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

Attachments

FileDateSize
testserver.js2013-05-28T22:28:26.000+0000249

Comments

  1. Ingo Muschenetz 2013-05-28

    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.
  2. Blain Hamon 2013-05-29

    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.
  3. Sabil Rahim 2013-05-29

    PR pending https://github.com/appcelerator/titanium_mobile/pull/4336 - master https://github.com/appcelerator/titanium_mobile/pull/4337 - 3_!_X
  4. Eric Merriman 2013-05-30

    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:
       E/TiHttpClient( 1414): (TiHttpClient-1) [4325,4325] HTTP Error (org.apache.http.conn.HttpHostConnectException): Connection to http://127.0.0.1:5678 refused
       E/TiHttpClient( 1414): org.apache.http.conn.HttpHostConnectException: Connection to http://127.0.0.1:5678 refused
       E/TiHttpClient( 1414): 	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
       E/TiHttpClient( 1414): 	at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
       E/TiHttpClient( 1414): 	at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
       E/TiHttpClient( 1414): 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
       E/TiHttpClient( 1414): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
       E/TiHttpClient( 1414): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
       E/TiHttpClient( 1414): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637)
       E/TiHttpClient( 1414): 	at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1271)
       E/TiHttpClient( 1414): 	at java.lang.Thread.run(Thread.java:856)
       E/TiHttpClient( 1414): Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 5678) after 5000ms: isConnected failed: ECONNREFUSED (Connection refused)
       E/TiHttpClient( 1414): 	at libcore.io.IoBridge.isConnected(IoBridge.java:214)
       E/TiHttpClient( 1414): 	at libcore.io.IoBridge.connectErrno(IoBridge.java:152)
       E/TiHttpClient( 1414): 	at libcore.io.IoBridge.connect(IoBridge.java:112)
       E/TiHttpClient( 1414): 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
       E/TiHttpClient( 1414): 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
       E/TiHttpClient( 1414): 	at java.net.Socket.connect(Socket.java:842)
       E/TiHttpClient( 1414): 	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
       E/TiHttpClient( 1414): 	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
       E/TiHttpClient( 1414): 	... 8 more
       E/TiHttpClient( 1414): Caused by: libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
       E/TiHttpClient( 1414): 	at libcore.io.IoBridge.isConnected(IoBridge.java:201)
       E/TiHttpClient( 1414): 	... 15 more
       D/TiAPI   ( 1414):  Connection to http://127.0.0.1:5678 refused
       I/ALERT   ( 1414): (KrollRuntimeThread) [45,4370] error
       
  5. Eric Merriman 2013-05-30

    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' }

JSON Source