Skip to content

Commit 96543a0

Browse files
committed
dm side changes and rust too
1 parent 5945bd8 commit 96543a0

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

dmsrc/http.dm

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
var/body
1717
var/headers
1818
var/url
19-
/// If present, the response body will be saved to this file.
20-
var/output_file = null
2119
/// If present, the request body will be read from this file.
2220
var/input_file = null
21+
/// If present, the response body will be saved to this file.
22+
var/output_file = null
23+
/// If present, request will timeout after this duration.
24+
var/timeout_seconds
2325

2426
var/_raw_response
2527

26-
/datum/http_request/proc/prepare(method, url, body = "", list/headers, output_file, input_file)
28+
/datum/http_request/proc/prepare(method, url, body = "", list/headers, output_file, input_file, timeout_seconds)
2729
if (!length(headers))
2830
headers = ""
2931
else
@@ -33,8 +35,9 @@
3335
src.url = url
3436
src.body = body
3537
src.headers = headers
36-
src.output_file = output_file
3738
src.input_file = input_file
39+
src.output_file = output_file
40+
src.timeout_seconds = timeout_seconds
3841

3942
/datum/http_request/proc/execute_blocking()
4043
_raw_response = rustg_http_request_blocking(method, url, body, headers, build_options())
@@ -52,11 +55,11 @@
5255
in_progress = TRUE
5356

5457
/datum/http_request/proc/build_options()
55-
if (output_file || input_file)
56-
. = json_encode(list(
57-
"output_filename" = output_file,
58-
"input_filename" = input_file
59-
))
58+
. = json_encode(list(
59+
"input_filename" = (input_file ? input_file : null),
60+
"output_filename" = (output_file ? output_file : null),
61+
"timeout_seconds"=(timeout_seconds ? timeout_seconds : null)
62+
))
6063

6164
/datum/http_request/proc/is_complete()
6265
if (isnull(id))
@@ -89,13 +92,14 @@
8992
return R
9093

9194
/datum/http_response
92-
/// The HTTP Status code - e.g., "404"
95+
/// The HTTP Status code - e.g., `"404"`
9396
var/status_code
94-
/// The response body - e.g., "{ "message": "No query results for xyz." }"
97+
/// The response body - e.g., `{ "message": "No query results for xyz." }`
9598
var/body
96-
/// A list of headers - e.g., list("Content-Type" = "application/json")
99+
/// A list of headers - e.g., list("Content-Type" = "application/json").
97100
var/list/headers
98101
/// If the request errored, this will be TRUE.
99102
var/errored = FALSE
100-
/// If the request errored, this will contain the error message - e.g., "status code 404"
103+
/// If there was a 4xx/5xx error or the request failed to be sent, this will be the error message - e.g., `"HTTP error: 404"`
104+
/// If it's the former, `status_code` will be set.
101105
var/error

src/http.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use ureq::http;
1313
#[derive(Deserialize)]
1414
struct RequestOptions {
1515
#[serde(default)]
16-
output_filename: Option<String>,
16+
input_filename: Option<String>,
1717
#[serde(default)]
18-
body_filename: Option<String>,
18+
output_filename: Option<String>,
1919
#[serde(default)]
2020
timeout_seconds: Option<u64>,
2121
}
@@ -120,12 +120,12 @@ fn construct_request(
120120
} else {
121121
RequestOptions {
122122
output_filename: None,
123-
body_filename: None,
123+
input_filename: None,
124124
timeout_seconds: None,
125125
}
126126
};
127127

128-
let body_to_send = if let Some(fname) = options.body_filename.clone() {
128+
let body_to_send = if let Some(fname) = options.input_filename.clone() {
129129
Some(std::fs::read(fname)?)
130130
} else if !body.is_empty() {
131131
Some(body.as_bytes().to_vec())

0 commit comments

Comments
 (0)