[TIMOB-19505] Ti.Network.HTTPClient Default addition of Appcelerator User-Agent header can impact success of network calls
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2016-07-21T01:44:07.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | TiAPI |
Labels | n/a |
Reporter | Bert Grantges |
Assignee | Eric Merriman |
Created | 2015-09-13T07:07:13.000+0000 |
Updated | 2017-03-23T22:30:01.000+0000 |
Description
On Android and iOS the addition of the default User-Agent string for each http network request is impacting the expected response of the network request.
The code that is causing the issue:
https://github.com/appcelerator/titanium_mobile/blob/4_1_X/android/modules/network/src/java/ti/modules/titanium/network/TiHTTPClient.java#L943
The issue seems to be that the protected endpoint is validating against known UserAgents and returning an error response if it is not an approved UserAgent string. Trying to set the user agent with Ti.Network.HTTPClient.setRequestHeader appends the header, but does not remove the default header.
Here is the like code on iOS that is causing the issue. https://github.com/appcelerator/titanium_mobile/blob/4_1_X/iphone/Classes/TiNetworkHTTPClientProxy.m#L50
From the docs: http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient, an "HTTP client object that (mostly) implements the XMLHttpRequest specification." From the XMLHttpRequest specification, values are appended: http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader()-method I don't know why the endpoint can't check for the new user agent. However, if we HAVE to overwrite the existing value, we need a new method to allow that.
Agreed with Ingo. we are appending the values since it's the industry standard so there's no reason why it's failing. However, without introducing a new method, you can try this.
Please confirm this works as expected. If so we will resolve as "Won't Fix"
@Ingo The workaround proposed by @Chee works for overriding the User-Agent. Can we assume this is future-proof on Ti SDK 5.X and 6.X ?
[~cng] ^^ fixing reference. Can you comment on the future-proofness of this?
Yes. it's future proof.
Closing ticket as Won't Fix with reference to the above comments.