Facepunch / garrysmod-requests

Feature requests for Garry's Mod
83 stars 24 forks source link

HTTPRequest progress, abort, and timeout #1888

Open TiberiumFusion opened 3 years ago

TiberiumFusion commented 3 years ago

Summary

Making http requests from Lua is very limited. There is no way to track the download progress of the server response, and there is also no way to abort the download if needed. This degrades the player experience when an addon needs to retrieve remote data that downloads slowly. This is not limited to large files. Players with slow/bad/censored/fluctuating internet can experience slow or impossible downloads (i.e. timeouts) on small data.

Progress

A. Could be a callback set in HTTPRequest, like function progress(code, loadedBytes, totalBytes). This could be called no more than once per tick, and only on ticks where loadedBytes increased. B. HTTPRequest could include an interface for getting the code, loadedBytes, and totalBytes values on demand.

Abort

HTTPRequest could include an interface for aborting the http request, like with progress as explained above.

Timeout

HTTPRequest could include a timeout value in seconds/milliseconds and a callback function for if a timeout occurs.

TiberiumFusion commented 3 years ago

Quite honestly I see absolutely no reason for these extremely basic features to missing in the first place, since they are already provided by ISteamHTTP.

https://partner.steamgames.com/doc/api/ISteamHTTP#GetHTTPResponseBodySize https://partner.steamgames.com/doc/api/ISteamHTTP#GetHTTPDownloadProgressPct https://partner.steamgames.com/doc/api/ISteamHTTP#SetHTTPRequestNetworkActivityTimeout https://partner.steamgames.com/doc/api/ISteamHTTP#GetHTTPRequestWasTimedOut

robotboy655 commented 2 years ago

Essentially duplicate of https://github.com/Facepunch/garrysmod-requests/issues/1340

robotboy655 commented 2 years ago

Implemented timeout field for HTTP() (NetworkActivityTimeout, not absolute timeout). When a request timeouts, the fail reason will now correctly be "timeout".

TiberiumFusion commented 2 years ago

@robotboy655 What is the units of timeout? Milliseconds? Seconds? https://wiki.facepunch.com/gmod/Structures/HTTPRequest doesn't say anything about the new timeout field yet.

robotboy655 commented 2 years ago

Seconds, just like the SteamAPI method you linked.