Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25789] Windows: HttpClient.onreadystatechange should be called right after ondatastream/onsendstream

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2018-12-10T21:28:26.000+0000
Affected Version/sRelease 7.0.0
Fix Version/sRelease 8.0.0
ComponentsWindows
Labelsparity
ReporterKota Iguchi
AssigneeKota Iguchi
Created2018-02-20T07:30:45.000+0000
Updated2018-12-11T12:27:34.000+0000

Description

HttpClient callbackTestForGETMethod and callbackTestForPOSTMethod [unit test](https://github.com/appcelerator/titanium-mobile-mocha-suite/blob/master/Resources/ti.network.httpclient.test.js#L377) shows onreadystatechange should be called right after ondatastream/onsendstream event to keep parity with iOS/Android.
var win = Ti.UI.createWindow({
    backgroundColor: 'white'
});

win.addEventListener('open', function () {
    var xhr = Ti.Network.createHTTPClient(),
    attempts = 3,
    sendStreamFinished = false,
    buffer;
    xhr.setTimeout(3e4);

    xhr.onreadystatechange = function () {
        Ti.API.info('onreadystatechange sendStreamFinished: ' + sendStreamFinished + ' DONE? ' + (this.readyState === this.DONE));
        if (this.readyState === this.DONE && sendStreamFinished) {
            Ti.API.info('finish');
        }
    };
    xhr.onsendstream = function (e) {
        Ti.API.info('onsendstream');
        Ti.API.info(e.progress + ' be.ok');
        if (e.progress >= 0.99) {
            sendStreamFinished = true;
        }
    };
    xhr.onerror = function (e) {
        if (attempts-- > 0) {
            Ti.API.warn('failed, attempting to retry request...');
            xhr.send();
        } else {
            Ti.API.warn(JSON.stringify(e, null, 2));
            Ti.API.warn(e.error || this.responseText);
        }
    };
    buffer = Ti.createBuffer({
        length: 1024 * 10
    }).toBlob();
    xhr.open('POST', 'http://www.httpbin.org/post');
    xhr.send({
        data: buffer,
        username: 'fgsandford1000',
        password: 'sanford1000',
        message: 'check me out'
    });
});

win.open();
Expected: finish should be printed.

Comments

  1. Kota Iguchi 2018-02-21

    https://github.com/appcelerator/titanium_mobile_windows/pull/1189
  2. Kota Iguchi 2018-10-11

    Seems like this makes LiveView unstable.
  3. Kota Iguchi 2018-11-15

    Attempt to fix issue with liveview: https://github.com/appcelerator/titanium_mobile_windows/pull/1318
  4. Josh Longton 2018-12-10

    *FR Passed*
  5. Samir Mohammed 2018-12-11

    Closing ticket, fix verified in SDK version 8.0.0.v20181210172243. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile_windows/pull/1318

JSON Source