|
16 | 16 | var/body
|
17 | 17 | var/headers
|
18 | 18 | var/url
|
19 |
| - /// If present, the response body will be saved to this file. |
20 |
| - var/output_file = null |
21 | 19 | /// If present, the request body will be read from this file.
|
22 | 20 | 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 |
23 | 25 |
|
24 | 26 | var/_raw_response
|
25 | 27 |
|
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) |
27 | 29 | if (!length(headers))
|
28 | 30 | headers = ""
|
29 | 31 | else
|
|
33 | 35 | src.url = url
|
34 | 36 | src.body = body
|
35 | 37 | src.headers = headers
|
36 |
| - src.output_file = output_file |
37 | 38 | src.input_file = input_file
|
| 39 | + src.output_file = output_file |
| 40 | + src.timeout_seconds = timeout_seconds |
38 | 41 |
|
39 | 42 | /datum/http_request/proc/execute_blocking()
|
40 | 43 | _raw_response = rustg_http_request_blocking(method, url, body, headers, build_options())
|
|
52 | 55 | in_progress = TRUE
|
53 | 56 |
|
54 | 57 | /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 | + )) |
60 | 63 |
|
61 | 64 | /datum/http_request/proc/is_complete()
|
62 | 65 | if (isnull(id))
|
|
89 | 92 | return R
|
90 | 93 |
|
91 | 94 | /datum/http_response
|
92 |
| - /// The HTTP Status code - e.g., "404" |
| 95 | + /// The HTTP Status code - e.g., `"404"` |
93 | 96 | 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." }` |
95 | 98 | 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"). |
97 | 100 | var/list/headers
|
98 | 101 | /// If the request errored, this will be TRUE.
|
99 | 102 | 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. |
101 | 105 | var/error
|
0 commit comments