(
ctx: &mut crate::vm::State<'gc>,
args: Vec<Value<'gc>>,
)
| 128 | } |
| 129 | |
| 130 | fn http_get<'gc>( |
| 131 | ctx: &mut crate::vm::State<'gc>, |
| 132 | args: Vec<Value<'gc>>, |
| 133 | ) -> Result<Value<'gc>, VmError> { |
| 134 | if args.is_empty() { |
| 135 | return Err(VmError::RuntimeError("URL required for GET request".into())); |
| 136 | } |
| 137 | |
| 138 | let url = args[0].as_string()?.to_string(); |
| 139 | let headers_map = if args.len() > 1 { |
| 140 | if let Value::Object(obj) = args[1] { |
| 141 | let borrowed = obj.borrow(); |
| 142 | parse_headers(borrowed.fields.clone()) |
| 143 | } else { |
| 144 | return Err(VmError::RuntimeError("Headers must be an object".into())); |
| 145 | } |
| 146 | } else { |
| 147 | HeaderMap::new() |
| 148 | }; |
| 149 | |
| 150 | // Execute request and process response in runtime |
| 151 | let result = Handle::current().block_on(async { |
| 152 | let response = make_request(reqwest::Method::GET, &url, headers_map, None) |
| 153 | .await |
| 154 | .map_err(|e| VmError::RuntimeError(format!("HTTP request failed: {}", e)))?; |
| 155 | |
| 156 | response_to_object(ctx.get_context(), response).await |
| 157 | })?; |
| 158 | |
| 159 | Ok(result) |
| 160 | } |
| 161 | |
| 162 | fn http_post<'gc>( |
| 163 | ctx: &mut crate::vm::State<'gc>, |
nothing calls this directly
no test coverage detected