Search Unity

UnityWebRequest progress always 0 on Oculus Go

Discussion in 'Multiplayer' started by Wattosan, Jun 4, 2019.

  1. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Hi,

    I am downloading large files in my Oculus Go app using the UnityWebRequest and DownloadHandlerFile classes. When testing via editor, the download progress is correct (values between 0-1). However, on Oculus Go, this value is always 0.

    What seems to be the issue?

    Thanks!
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Try also checking the downloadedBytes property and Content-Length header. Progress will be 0 if expected length is not known.
     
  3. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    The downloadedBytes property updates nicely on both playforms, the Unity Editor and Oculus Go. However, the UnityWebRequest.GetResponseHeaders() dictionary is null in both the editor and the Oculus Go. If I try to get the Content-Length header manually via uwr.GetResponseHeader("Content-Length"), I get a Null.

    So it is kind of weird that inside the Unity Editor the download progress updates, even though the headers dictionary is null. I have checked the uri I use in chrome and Insomnia and they both do return headers, along with the Content-Length entry (which is also correct).

    I'll add the code sample just in case:
    Code (CSharp):
    1. DownloadHandlerFile downloadHandler = new DownloadHandlerFile(path);
    2. downloadHandler.removeFileOnAbort = true;
    3.  
    4. UnityWebRequest uwr = new UnityWebRequest(uri);
    5. uwr.method = UnityWebRequest.kHttpVerbGET;
    6. uwr.downloadHandler = downloadHandler;
    7.  
    8. uwr.SendWebRequest();
    9.  
    10. Debug.Log("RESPONSE CONTENT LENGTH HEADER: " + uwr.GetResponseHeader("Content-Length")); // this returns null
    11.  
    12. if (uwr != null && uwr.GetResponseHeaders() != null)
    13. {
    14.     foreach (KeyValuePair<string, string> header in uwr.GetResponseHeaders())
    15.     {
    16.         Debug.Log(header.Key + ":" + header.Value);
    17.     }
    18. }
    19.  
    20. while (!uwr.isDone)
    21. {
    22.     float downloadProgress = (float)uwr.downloadedBytes / (float)videoSize;
    23.     float progress = (float)((int)(downloadProgress * 1000) / 10.0f);
    24.     yield return null;
    25. }
    26.  
    27. if (uwr.isNetworkError || uwr.isHttpError)
    28. {
    29.     Debug.LogError(uwr.error);
    30. }
    31. else
    32. {
    33.     Debug.Log("Downloaded file to " + path.Replace("/", "\\"));
    34. }
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    You have to wait for download to make at least some progress before checking the headers. You are now checking immediately after send, so the response hasn't yet arrived.
     
  5. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    You were correct about having to wait. I waited till 0.1% was complete and then the header dictionary is available. However, there is still a problem. For some reason the headers do not contain the "Content-Length" entry when playing with Oculus Go. It is available when playing through Unity Editor. All other headers are present plus the Android has some additional headers.

    Accept-Ranges:bytes
    Content-Length:159606348 (Not present in OCULUS GO)
    Content-Security-Policy:block-all-mixed-content
    Content-Type:video/mp4
    Date:Wed, 05 Jun 2019 08:33:54 GMT
    Etag: (I hid it)
    Last-Modified:Sat, 15 Dec 2018 15:45:31 GMT
    Server: (I hid it)
    Transfer-Encoding:chunked (Not present in UNITY EDITOR)
    Vary:Accept-Encoding,Origin
    X-Amz-Meta-User.xdg.origin.url: (I hid it)
    X-Amz-Meta-User.xdg.referrer.url: (I hid it)
    X-Amz-Request-Id: (I hid it)
    X-Android-Received-Millis:1559723584923 (Not present in UNITY EDITOR)
    X-Android-Response-Source:NETWORK 200 (Not present in UNITY EDITOR)
    X-Android-Selected-Protocol:http/1.1 (Not present in UNITY EDITOR)
    X-Android-Sent-Millis:1559723584733 (Not present in UNITY EDITOR)
    X-Minio-Deployment-Id: (I hid it)
    X-Xss-Protection:1; mode=block

    Since "Transfer-Encoding:chunked" is available only on android perhaps this is the problem. I am getting chunked data and the content-length header is available from somewhere else.
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Yes, chunked transfer would make progress unavailable, because we don't know how much data is supposed to arrive.
     
  7. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Why is it chunked when downloading to Oculus Go but not chunked when downloading via Unity Editor?
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    You need to examine the traffic in order to know that. If URL is the same, then it's probably some header in request, that is set automatically.
     
  9. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Any ideas how to check the automatically set request headers?
     
  10. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Send the same request to some different URL that would tell them to you.
    This could help: https://httpbin.org/get
     
  11. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    The headers that reach the server look like the following (server log):
    [REQUEST objectAPIHandlers.GetObjectHandler-fm] [xxx.xxx] [2019-06-09 14:41:12 +0000]
    GET /movies/xxx.mp4
    Host: xxx
    X-Forwarded-Port: 443
    X-Forwarded-Proto: https
    X-Forwarded-Server: xxx
    X-Unity-Version: 2019.1.4f1
    User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.1.2; Pacific Build/N2G48H)
    Accept-Encoding: gzip
    X-Forwarded-For: xxx
    X-Forwarded-Host: xxx
    X-Real-Ip: xxx

    And headers that are added to the response (server log):
    [RESPONSE] [xxx.xxx] [2019-06-09 14:41:26 +0000]
    200 OK
    Vary: Origin
    Content-Security-Policy: block-all-mixed-content
    X-Minio-Deployment-Id: xxx
    Server: MinIO/RELEASE.2019-06-04T01-15-58Z
    Content-Length: 1862201179
    Content-Type: video/mp4
    X-Xss-Protection: 1; mode=block
    X-Amz-Request-Id: xxx
    Accept-Ranges: bytes
    Last-Modified: Sat, 15 Dec 2018 17:08:38 GMT
    ETag: "xxx"

    Any ideas what might be the issue here?

    As a side note, it would really help if it was possible to iterate over all the headers of the request. Even those created automatically by Unity.
     
  12. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    I do see Content-Length in response. I also see ETag header. Is that exact headers from the problematic request?
     
  13. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    No, some automatic headers are added not by Unity, but by an underlying system backend.
     
  14. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Yes, it is with the same request. It seems that if the response reaches Oculus Go, it is split up for some reason. Because the headers logged from the Unity app in Oculus Go have the additional "Transfer-Enconding, chunked" header set.