Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19505] Ti.Network.HTTPClient Default addition of Appcelerator User-Agent header can impact success of network calls

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2016-07-21T01:44:07.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTiAPI
Labelsn/a
ReporterBert Grantges
AssigneeEric Merriman
Created2015-09-13T07:07:13.000+0000
Updated2017-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.

Comments

  1. Bert Grantges 2015-09-13

    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
  2. Ingo Muschenetz 2015-09-14

    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.
  3. Chee Kiat Ng 2015-09-15

    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.
       request.setRequestHeader('User-Agent', null); //this deletes any existing value
       request.setRequestHeader('User-Agent', 'yourNewAgent');
       
  4. Ingo Muschenetz 2015-09-28

    Please confirm this works as expected. If so we will resolve as "Won't Fix"
  5. Ygor Lemos 2016-07-20

    @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 ?
  6. Ingo Muschenetz 2016-07-20

    [~cng] ^^ fixing reference. Can you comment on the future-proofness of this?
  7. Chee Kiat Ng 2016-07-21

    Yes. it's future proof.
  8. Lee Morris 2017-03-23

    Closing ticket as Won't Fix with reference to the above comments.

JSON Source