Add online_awaited_request function
This commit is contained in:
parent
203018db6f
commit
2200de33fa
2 changed files with 14 additions and 0 deletions
|
@ -20,6 +20,12 @@ The returned `Dictionary` has the following structure (example):
|
|||
| ---------------------------------------------------------------------- The HTTP response code
|
||||
------------------------------------------------------------------------------------ Equal to @GlobalScope.Error. If not 0/Error.OK = the request failed
|
||||
```
|
||||
### *Variant* <u>oneline_awaited_request</u>(*String* <u>url</u>, *bool* <u>return_utf8</u> = *true*, *bool* <u>ignore_http_code</u> = *false* *HTTPClient.Method* <u>method</u> = *HTTPClient.Method.METHOD_GET*, *PackedStringArray* <u>headers</u> = *PackedStringArray([])*, *String* <u>data</u> = *""*)
|
||||
Returns a file from the internet without returning the godot code, http code or headers. Useful for oneliners.
|
||||
|
||||
Returns `null` on error. To ignore HTTP errors (ie. non-200 statuses) set `ignore_http_code` to `true`.
|
||||
Returns a UTF-8 string with `return_utf8` turned on, returns bytes when turned off.
|
||||
|
||||
### *Array[Dictionary]* <u>batch_awaited_request</u>(*PackedStringArray* <u>urls</u>, *HTTPClient.Method* <u>method</u> = *HTTPClient.Method.METHOD_GET*, *PackedStringArray* <u>headers</u> = *PackedStringArray([])*, *String* <u>data</u> = *""*)
|
||||
Requests multiple file from the internet, awaitable.
|
||||
|
||||
|
|
|
@ -40,6 +40,14 @@ func awaited_request(url: String, method: HTTPClient.Method = HTTPClient.Method.
|
|||
list_complete.erase(id)
|
||||
return dldata
|
||||
|
||||
func oneline_awaited_request(url: String, return_utf8: bool = true, ignore_http_code: bool = false, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Variant:
|
||||
var dldata: Dictionary = await awaited_request(url, method, headers, data)
|
||||
if dldata["result"] != Error.OK: return null
|
||||
elif !ignore_http_code and dldata["http_code"] != 200: return null
|
||||
else:
|
||||
if return_utf8: return dldata["body_utf8"]
|
||||
else: return dldata["body"]
|
||||
|
||||
func batch_awaited_request(urls: PackedStringArray, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Array[Dictionary]:
|
||||
logger.verbf("Edl", "Creating " + str(urls.size()) + " awaited request(s)")
|
||||
var dldata: Array[Dictionary]= []
|
||||
|
|
Loading…
Reference in a new issue