Merge pull request #16931 from AffectedArc07/new-rust-g

Upgrades RUSTG
This commit is contained in:
variableundefined
2021-10-17 13:24:04 -05:00
committed by GitHub
8 changed files with 128 additions and 52 deletions
+16 -3
View File
@@ -19,6 +19,8 @@
var/headers
/// URL that the request is being sent to
var/url
/// If present, response body will be saved to this file.
var/output_file
/// The raw response, which will be decoeded into a [/datum/http_response]
var/_raw_response
/// Callback for executing after async requests. Will be called with an argument of [/datum/http_response] as first argument
@@ -42,7 +44,7 @@ THE METHODS IN THIS FILE ARE TO BE USED BY THE SUBSYSTEM AS A MANGEMENT HUB
* * _body - The body of the request, if applicable
* * _headers - Associative list of HTTP headers to send, if applicab;e
*/
/datum/http_request/proc/prepare(_method, _url, _body = "", list/_headers)
/datum/http_request/proc/prepare(_method, _url, _body = "", list/_headers, _output_file)
if(!length(_headers))
headers = ""
else
@@ -51,6 +53,7 @@ THE METHODS IN THIS FILE ARE TO BE USED BY THE SUBSYSTEM AS A MANGEMENT HUB
method = _method
url = _url
body = _body
output_file = _output_file
/**
* Blocking executor
@@ -60,7 +63,7 @@ THE METHODS IN THIS FILE ARE TO BE USED BY THE SUBSYSTEM AS A MANGEMENT HUB
*/
/datum/http_request/proc/execute_blocking()
CRASH("Attempted to execute a blocking HTTP request")
// _raw_response = rustg_http_request_blocking(method, url, body, headers)
// _raw_response = rustg_http_request_blocking(method, url, body, headers, build_options())
/**
* Async execution starter
@@ -73,7 +76,7 @@ THE METHODS IN THIS FILE ARE TO BE USED BY THE SUBSYSTEM AS A MANGEMENT HUB
if(in_progress)
CRASH("Attempted to re-use a request object.")
id = rustg_http_request_async(method, url, body, headers)
id = rustg_http_request_async(method, url, body, headers, build_options())
if(isnull(text2num(id)))
_raw_response = "Proc error: [id]"
@@ -81,6 +84,16 @@ THE METHODS IN THIS FILE ARE TO BE USED BY THE SUBSYSTEM AS A MANGEMENT HUB
else
in_progress = TRUE
/**
* Options builder
*
* Builds options for if we want to download files with SShttp
*/
/datum/http_request/proc/build_options()
if(output_file)
return json_encode(list("output_filename" = output_file, "body_filename" = null))
return null
/**
* Async completion checker
*