Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24748] Android: HTTPClient - can't use streaming mode with authentication

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-06-07T00:43:16.000+0000
Affected Version/sRelease 6.1.0
Fix Version/sRelease 6.1.1
Componentsn/a
Labelsmerge-6.1.1, regression
ReporterJorge Macias Garcia
AssigneeJoshua Quick
Created2017-05-30T15:04:38.000+0000
Updated2020-10-29T21:42:41.000+0000

Description

*Problem* Apparently HTTP streaming can't be set when authentication is used. The retry mechanism of the basic authentication throws a HttpRetryException when the request body is streamed. *Test case* _Provided by Jorge Macias in Slack_
var window = Ti.UI.createWindow();
var button1 = Ti.UI.createButton({title:"Basic request", top: 30});
window.add(button1);

button1.addEventListener('click', prepareRequest);

function prepareRequest(e) {
    request(true);
}

/**
* Make a request
* @method  request
* @param   {boolean} withCredentials Flag for make a auth request or not
*/
function request(withCredentials) {
    var client,
      config,
      url,
      data;

    data = {
      message: 'This is my message'
    };

    config = {
      timeout: 5000
    };

    if (withCredentials) {
      url = 'https://srvasic.upv.es/recursos/error401.asp';
      //config.withCredentials = true;
      config.username = 'user';
      config.password = 'p$wd';
    }

    console.log('HTTP CLIENT CONFIG ' + JSON.stringify(config));

    client = Ti.Network.createHTTPClient(config);
    client.setOnload(success);
    client.setOnerror(error);

    try {
      console.log('URL: ' + url);
      client.open('POST', url);
    } catch (e) {
      console.log('error opening client');
      console.log(JSON.stringify(e));
    }

    try {
      client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    } catch (e) {
      console.log('error setting request headers');
      console.log(JSON.stringify(e));
    }

    try {
      client.send(data);
    } catch (e) {
      console.log('error sending data');
      console.log(JSON.stringify(e));
    }
}

/**
* HttpClient Success Callback
* @method  success
* @param   {object} e Callback Event
*/
function success(e) {
    console.log('Success callback: ' + this.responseText);
}

/**
* HttpClient Error Callback
* @method  error
* @param   {object} e Callback Event
*/
function error(e) {
    console.log('Error callback : ' + e.error);
}

window.open();
*Logs*
E/TiHTTPClient: (TiHttpClient-1) [53661,53661] HTTP Error (java.net.HttpRetryException): Cannot retry streamed HTTP body
                java.net.HttpRetryException: Cannot retry streamed HTTP body
                    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:417)
                    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:501)
                    at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
                    at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java)
                    at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1224)
                    at java.lang.Thread.run(Thread.java:818)

Comments

  1. Yordan Banev 2017-06-01

    PR: https://github.com/appcelerator/titanium_mobile/pull/9104
  2. Abir Mukherjee 2017-06-06

    Tested with this environment: Node Version: 6.10.3 NPM Version: 3.10.10 Mac OS: 10.12.4 Appc CLI: 6.2.2 Appc CLI NPM: 4.2.9 Titanium SDK version: PR/9104 Appcelerator Studio, build: 4.9.0.201705302345 Xcode 8.3.2 FR Passed. After verifying the regresssion (no errors in SDK 6.0.4, but errors in SDK 6.1.0) I tested with the above testcase, and no errors were seen in the latest fix. Fixes are found in: 6.1.1.v20170606173149 6.2.0.v20170606155020
  3. Joshua Quick 2017-06-06

    PR (6.1.X): https://github.com/appcelerator/titanium_mobile/pull/9119
  4. Michael Gangolf 2017-08-19

    A lot of log messages like this appear now: {noformat} D/TiHTTPClient(24488): (main) [2081,3720] Setting ready state to 1 D/TiHTTPClient(24488): (TiHttpClient-34) [61,3781] Setting ready state to 2 D/TiHTTPClient(24488): (TiHttpClient-34) [0,3781] Setting ready state to 3 D/TiHTTPClient(24488): (TiHttpClient-34) [17,3798] Setting ready state to 4 D/TiHTTPClient(24488): (main) [55,3853] Setting ready state to 1 {noformat} because in this line: https://github.com/appcelerator/titanium_mobile/pull/9119/files#diff-1e01f142e85df58a3e89a93008e5a21eL446 Log.DEBUG_MODE was removed. Was this done by intention or just for testing purpose?
  5. Yordan Banev 2017-08-21

    [~michael] It was for testing purpose.
  6. Yordan Banev 2017-08-22

    [~michael] For the fix: PR: https://github.com/appcelerator/titanium_mobile/pull/9342 6_2_X: https://github.com/appcelerator/titanium_mobile/pull/9343

JSON Source