Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Failed to load resource: Request header field Accept-Encoding is not allowed (Safari)

Discussion in 'WebGL' started by liortal, Apr 3, 2016.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,555
    We are sending requests to receive FB user images in our WebGL version of our game.

    The URL we send has the following format: https://graph.facebook.com/10153195058465905/picture?redirect=true&height=60&type=normal&width=65

    (replace my id with any Facebook user id)

    The error we're seeing is something like this:
    This only happens on Safari. Is this a limitation of WebGL? has anyone else faced this issue ?
     
  2. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    Hello liortal.

    I have just been able to successfully download your exact image using WWW from WebGL in Safari.
    Could you provide your exact code and Unity/Safari versions?
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,555
    The issue is that the request to FB results in a redirect. The redirected request contains headers that are not handled correctly by Safari.

    Here is roughly the code we use:
    Code (CSharp):
    1. private const string IMAGE_URL_FORMAT = @"https://graph.facebook.com/{0}/picture?redirect=true&height={1}&type=normal&width={2}";
    2.  
    3. var www = new WWW(string.Format(IMAGE_URL_FORMAT, fbId, 65, 65));
    4. yield return www;
     
  4. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    Thank you. I was able to reproduce the issue. Could you please create a bug report for this and post the case number here?
     
  5. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,555
    Reported a bug: (Case 785491) Failing to download FB images on WebGL in Safari
     
  6. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    Thank you. For now you may use the following (or similar) workaround: http://forum.unity3d.com/threads/on...trol-allow-origin-header.385628/#post-2508391
    Just add
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    if you decide to use php proxy with curl.
    Or you may as well use
    $context = stream_context_create($request_headers);
    $response = file_get_contents($_GET["url"], false, $context);

    noted in other comments in that thread.
     
    Last edited: Apr 4, 2016
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,555
    Our game client directly contacts Facebook, we don't have a proxy server in the middle. For the time being we worked-around the issue by avoiding the automatic redirect. We receive a JSON response from Facebook with the actual image URL and then we load that URL to get the image.
     
  8. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    That's great, means you don't need any additional workaround here. But just in case, you may still consider using a proxy server when you need to download a resource from a server that does not provide proper CORS headers.
     
  9. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    This issue is not specific to WebGL, as you can see in the console of the following example: https://jsfiddle.net/ho26kzap/

    I'm not sure if there is any trick that can make it work as you expect without any workarounds, but the actual problem is the following:
    The redirected request (from https://graph.facebook.com/10153195058465905/picture?redirect=true&height=60&type=normal&width=65 to https://scontent.xx.fbcdn.net/hprof...=58294f494cd76b395a5d3190e2e1d0a6&oe=578D7AC9) is being preflighted in Safari with OPTIONS and Access-Control-Request-Headers: accept-encoding, origin, accept-language, however, https://scontent.xx.fbcdn.net responds with Access-Control-Allow-Headers: RANGE. Had the https://scontent.xx.fbcdn.net responded with Access-Control-Allow-Headers: range, accept-encoding, origin, accept-language, the request would succeed.

    Similar issue can be seen in development builds of other browsers (i.e. in Chrome Canary, due to the usage of access-control-request-headers: x-devtools-emulate-network-conditions-client-id in preflighted request)
     
    Last edited: Apr 4, 2016