Search Unity

UnityWebRequest, Setting 'user-agent' is not allowed

Discussion in 'Scripting' started by SamuelAsherRivello, Sep 15, 2016.

?

Do you recommend Unity change the UnityWebRequest API and allow custom values for 'user-agent'?

  1. Yes

    77 vote(s)
    93.9%
  2. No

    1 vote(s)
    1.2%
  3. No opinion

    4 vote(s)
    4.9%
  1. SamuelAsherRivello

    SamuelAsherRivello

    Joined:
    Jan 16, 2011
    Posts:
    41
    UnityWebRequest is meant as a replacement for WWW.

    According to UnityWebRequest Documentation;

    https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.SetRequestHeader.html

    "The user-agent and x-unity-version headers are automatically set by Unity and may not be set to custom values."

    This limits development options for our team. Historically, we populate 'user-agent' with a custom value.
    1. Is this limitation acceptable to the community in general?
    2. Any workarounds to recommend?
     
  2. undersun81

    undersun81

    Joined:
    Feb 15, 2013
    Posts:
    5
    If we don't have possibility to override or add data to User-Agent then we can't use GZip compression with Google Apps Engine.
    From GAE docs:
    "Custom clients can indicate that they are able to receive compressed responses by specifying both Accept-Encoding and User-Agent headers with a value of gzip."
     
  3. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    The inflexible headers seem to be a problem if dealing with AWS authentication, too - where you're expected to have total control over the HTTP request, or at least total knowledge of what goes into it, in order to generate a signature.

    But if you bypass UnityWebRequest when downloading AssetBundles, and implement the HTTP download yourself, you're locked out from using the asset bundle caching functionality, as you can't manually put data in that cache.

    And you're also prevented from using the hashes in manifest bundles, as there's no documented way to compute a Hash128 from the data you've downloaded.

    (Edit: Turns out that there's multiple ways to authenticate with AWS, and this one looks like it should be fine in cases where you can't fully control the request headers)
     
    Last edited: Mar 31, 2017
  4. studiogameever

    studiogameever

    Joined:
    Jul 21, 2020
    Posts:
    1
    use it like that and you will be able to populate


    UnityWebRequest webRequest = new UnityWebRequest();
    webRequest = UnityWebRequest.Get(url);
    webRequest.SetRequestHeader("Accept", "*/*");
    webRequest.SetRequestHeader("Accept-Encoding", "gzip, deflate");
    webRequest.SetRequestHeader("User-Agent", "runscope/0.1");
     
    chmodseven and MSQTobi like this.