Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16554] iOS: NewHTTPClient missing response from ondatastream callback

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-03-07T21:49:32.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 05, 2014 Sprint 05 API, Release 3.3.0
ComponentsiOS
Labelsnetwork, qe-closed-3.3.0, qe-testadded
ReporterPedro Enrique
AssigneePedro Enrique
Created2014-03-05T18:58:26.000+0000
Updated2014-06-19T12:42:49.000+0000

Description

The new HTTPClient implementation is missing the response details on the ondatastream, onreadystatechange, and onsendstream callbacks. Run this code to verify the fix. Compare with the old HTTPClient by renaming the Network.createNewHTTPClient() to just Network.createHTTPClient() in the code here. Sample code:
var win = Titanium.UI.createWindow({
	backgroundColor: '#CCC'
});


var output = Ti.UI.createView({
	layout: 'vertical',
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE,
	left: 20
});

var labelStatus = Ti.UI.createLabel({
	top: 5,
	color: 'red',
	left: 0,
	text: ''
})
var labelConnected = Ti.UI.createLabel({
	top: 5,
	color: 'yellow',
	left: 0,
	text: ''
})
var labelReadyState = Ti.UI.createLabel({
	top: 5,
	color: 'green',
	left: 0,
	text: ''
})
var labelResponseData = Ti.UI.createLabel({
	top: 5,
	color: 'blue',
	left: 0,
	text: ''
})
var labelConnectionType = Ti.UI.createLabel({
	top: 5,
	color: 'purple',
	left: 0,
	text: ''
})
var labelLocation = Ti.UI.createLabel({
	top: 5,
	color: 'orange',
	left: 0,
	text: ''
})
var labelContentLength = Ti.UI.createLabel({
	top: 5,
	color: 'brown',
	left: 0,
	text: ''
});
var labelProgress = Ti.UI.createLabel({
	top: 5,
	color: 'black',
	left: 0,
	text: ''
})
output.add(labelStatus);
output.add(labelConnected);
output.add(labelReadyState);
output.add(labelResponseData);
output.add(labelConnectionType);
output.add(labelLocation);
output.add(labelContentLength);
output.add(labelProgress);

win.add(output);

var startButton = Ti.UI.createButton({
	title: 'Start Test',
	bottom: 20
});

win.add(startButton);

updateLabels({
	status:'',
	connected:'',
	readyState:'',
	responseData:'',
	connectionType:'',
	location:'',
	getResponseHeader:function(){return ''; },
	progress: 0
});


function updateLabels(xhr) {
	labelStatus.text 		= 'status: ' + xhr.status + '\n';
	labelConnected.text 	= 'connected: ' + xhr.connected + '\n';
	labelReadyState.text 	= 'readyState: ' + xhr.readyState + '\n';
	labelResponseData.text 	= 'responseData: ' + xhr.responseData + '\n';
	labelConnectionType.text = 'connectionType: ' + xhr.connectionType + '\n';
	labelLocation.text 		= 'location: ' + xhr.location + '\n';
	labelContentLength.text = 'content-length: ' + xhr.getResponseHeader('Content-Length');
	labelProgress.text 		= 'progress: ' + xhr.progress;
}
startButton.addEventListener('click', function(){

	var xhr = Titanium.Network.createNewHTTPClient();
	updateLabels(xhr);
	var readyState = -1;
	xhr.onload = function()
	{
		updateLabels(xhr);
	};
	xhr.ondatastream = function(e)
	{
		if (xhr.readyState > readyState)
		{
			xhr.progress = e.progress;
			updateLabels(xhr);
		}

	};
	// open the client
	xhr.open('GET','http://www.appcelerator.com/assets/The_iPad_App_Wave.pdf');

	// send the data
	xhr.send();
});
	
win.open();

Comments

  1. Pedro Enrique 2014-03-05

    Pending PR: https://github.com/appcelerator/titanium_mobile/pull/5429
  2. Olga Romero 2014-04-22

    Tested the above code, changed var xhr as suggested by [~penrique] and verified the expected behavior with: Mac osx 10.9.2 Mavericks Appcelerator Studio, build: 3.2.3.201404162038 Titanium SDK, build 3.3.0.v20140418162516 Node.JS Version: v0.10.13 NPM Version: 1.3.2 ├── acs@1.0.14 ├── alloy@1.3.1 ├── node-appc@0.2.0 ├── npm@1.3.2 ├── titanium@3.3.0-dev └── titanium-code-processor@1.1.1-beta1 npm -g ls titanium: /usr/local/lib └── titanium@3.3.0-dev (git://github.com/appcelerator/titanium.git#93414d143051df4578b7aa42670008e5ef02c422) XCode Version: 5.1.1 Device: iPhone 5S iOS version 7.0

JSON Source