Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25686] HTTPClient compliance with XMLHttpRequest specifications

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 7.0.0, Release 8.0.2
Fix Version/sn/a
Componentsn/a
Labelsandoid, engSchedule, httpclient, ios, spec
ReporterSergey Volkov
AssigneeUnknown
Created2018-01-16T13:38:48.000+0000
Updated2019-07-30T15:38:49.000+0000

Description

function getXhr() {
  if (typeof Ti !== 'undefined') {
      return Ti.Network.createHTTPClient();
  }
  if (typeof XMLHttpRequest) {
      return new XMLHttpRequest();
  }
  throw Error('Unknown environment');
}
var xhr = getXhr();
xhr.onload = function () {console.log('onload' + ' ' + xhr.status)};
xhr.onerror = function () {console.log('onerror' + ' ' + xhr.status)};
xhr.addEventListener('load', function() {console.log('load' + ' ' + xhr.status)});
xhr.addEventListener('error', function() {console.log('error' + ' ' + xhr.status)});

xhr.open('GET', 'http://www.httpbin.org/status/400'); //returns 400 status
xhr.send();
Console output in browser: {noformat} onload 400 load 400 {noformat} Output in Titanium: {noformat}onerror{noformat}

Comments

  1. Hans Knöchel 2018-01-16

    Hey [~s.volkov], can you add a bit more context here? 400-500 error codes usually return in the onerror callback. The load and error *events* should not even exist. But I am open for improvements here, although it would mean a quite huge breaking change for advanced use-cases.
  2. Sergey Volkov 2018-01-16

    I'm not insisting on events implementation (nevertheless, it would be nice to have fullspec compilant xhr). Problem is that XMLHttpRequest does not call onerror callback on status >=400, but Titanium does. You can try example above in any browser (of course in "www.httpbin.org" origin).

JSON Source