mapbox / mapbox-sdk-cs

C# libraries for Mapbox API layer
https://mapbox.github.io/mapbox-sdk-cs/
Other
20 stars 11 forks source link

Optimize http requests - IFileSource: replace UnityWebRequest with WWW #30

Closed wilhelmberg closed 7 years ago

wilhelmberg commented 7 years ago

refs #11

background: https://github.com/mapbox/mapbox-go/issues/28

http://answers.unity3d.com/answers/1172963/view.html Apple blocks access to HTTPS through non-approved code paths, and HttpWebRequest is not part of the approved code path. We switched our implementation around and used Unity.WWW to get around the problem.

https://docs.unity3d.com/ScriptReference/WWW.html

wilhelmberg commented 7 years ago

hmm! Getting 401 Unauthorized using WWW: image

The URL works in the browser and with UnityWebRequest.

david-rhodes commented 7 years ago

I spent 5 minutes converting UnityWebRequest into WWW last night and saw errors on iOS, as well. It seemed to work in the editor, though.

Rather than replacing UnityWebRequest, I think we should make a different concrete version of IFileSource that uses WWW. There may be a fix for all this in the near future (being hopeful here).

The other thing to look out for with WWW is making it cancelable. I'm very surprised there isn't more discussion about this on the internet, given how much this affects so many developers . . .

wilhelmberg commented 7 years ago

Oops, my bad I added the access_token to the request url twice. It does work with WWW.

The other thing to look out for with WWW is making it cancelable. I'm very surprised there isn't more discussion about this on the internet, given how much this affects so many developers . . .

Yes, noticed that too - that's not good. Luckily we don't transfer a lot of data per request.

david-rhodes commented 7 years ago

If you throw this on a branch today, I can test on iOS. 😄

wilhelmberg commented 7 years ago

Working branch is here: https://github.com/mapbox/mapbox-sdk-unity-core/tree/optimize-http-requests

It's not yet completely usable, but that's the HTTPRequest.cs using WWW.

Maybe you could just replace the file? Should be a drop-in replacement.

EDIT --> updated Response.cs is also needed as I added the response headers <-- EDIT.

david-rhodes commented 7 years ago

FWIW, this should not be a replacement, but an additional option.