[TIMOB-19978] iOS: HTTPClient sets content-length while the body is empty or undefined with GET
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 5.0.2 |
Fix Version/s | n/a |
Components | iOS |
Labels | Community, engTriage, headers, httpclient, ios |
Reporter | Rene Pot |
Assignee | Unknown |
Created | 2014-10-22T15:01:20.000+0000 |
Updated | 2019-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.
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
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.