Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19978] iOS: HTTPClient sets content-length while the body is empty or undefined with GET

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 5.0.2
Fix Version/sn/a
ComponentsiOS
LabelsCommunity, engTriage, headers, httpclient, ios
ReporterRene Pot
AssigneeUnknown
Created2014-10-22T15:01:20.000+0000
Updated2019-11-18T22:58:59.000+0000

Description

On iOS, when initiating a call with an empty body on the send object, the content length is being set to 0. On Android this problem does not seem to occur However, as the body is actually empty, it should not set a content length at all. Test case:
       config = {
           onload: _.partial(_response, true),
           onerror: _.partial(_response, false),
           ondatastream: progressHandler,
           onsendstream: progressHandler,
           onreadystatechange: stateChangeHandler,
           timeout: options.timeout || 10000
       };
     var httpClient =  Ti.Network.createHTTPClient(config);
     httpClient.open('GET', path);
     httpClient.setRequestHeader("Content-Type", "application/json");
     var body = undefined; //or var body = '';
     httpClient.send(body); 
When this is send, the request header is going to be "content-length: 0", which should not be the case, the header should be omitted.

Comments

  1. Shuo Liang 2014-10-24

    Hi, 1. The body you mentioned can be only used in "POST" method for passing data. Here is the doc. [http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient-method-send] 2. When you use a "GET" Method in your request, the body data should be empty, as all the data information contains in url. So content-length is necessary for http request header even the body is empty. Hope this will help you. Regards, Shuo
  2. Rene Pot 2014-10-24

    Hi thanks. Yes I know. But I've already emtied the variable for that reason. I use the same lib for all my calls, and on Android it also works fine. It should just not set content length to 0. It should be a missing header. Therefore this is actually a bug.

JSON Source