diff --git a/docs/docs/reference/edl.md b/docs/docs/reference/edl.md index 9302dfc..8da47e0 100644 --- a/docs/docs/reference/edl.md +++ b/docs/docs/reference/edl.md @@ -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* oneline_awaited_request(*String* url, *bool* return_utf8 = *true*, *bool* ignore_http_code = *false* *HTTPClient.Method* method = *HTTPClient.Method.METHOD_GET*, *PackedStringArray* headers = *PackedStringArray([])*, *String* data = *""*) +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]* batch_awaited_request(*PackedStringArray* urls, *HTTPClient.Method* method = *HTTPClient.Method.METHOD_GET*, *PackedStringArray* headers = *PackedStringArray([])*, *String* data = *""*) Requests multiple file from the internet, awaitable. diff --git a/src/Edl.gd b/src/Edl.gd index 4162c97..36d2e41 100644 --- a/src/Edl.gd +++ b/src/Edl.gd @@ -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]= []