MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / http_put

Function http_put

aiscript-vm/src/stdlib/http.rs:196–229  ·  view source on GitHub ↗
(
    ctx: &mut crate::vm::State<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

194}
195
196fn http_put<'gc>(
197 ctx: &mut crate::vm::State<'gc>,
198 args: Vec<Value<'gc>>,
199) -> Result<Value<'gc>, VmError> {
200 if args.len() < 2 {
201 return Err(VmError::RuntimeError(
202 "URL and body required for PUT request".into(),
203 ));
204 }
205
206 let url = args[0].as_string()?.to_string();
207 let body = args[1].as_string()?.to_string();
208 let headers = if args.len() > 2 {
209 if let Value::Object(obj) = args[2] {
210 obj.borrow().fields.clone()
211 } else {
212 return Err(VmError::RuntimeError("Headers must be an object".into()));
213 }
214 } else {
215 HashMap::default()
216 };
217
218 let headers_map = parse_headers(headers);
219
220 let result = Handle::current().block_on(async {
221 let response = make_request(reqwest::Method::PUT, &url, headers_map, Some(body))
222 .await
223 .map_err(|e| VmError::RuntimeError(format!("HTTP request failed: {}", e)))?;
224
225 response_to_object(ctx.get_context(), response).await
226 })?;
227
228 Ok(result)
229}
230
231fn http_delete<'gc>(
232 ctx: &mut crate::vm::State<'gc>,

Callers

nothing calls this directly

Calls 9

RuntimeErrorClass · 0.85
parse_headersFunction · 0.85
make_requestFunction · 0.85
response_to_objectFunction · 0.85
lenMethod · 0.80
as_stringMethod · 0.80
get_contextMethod · 0.80
cloneMethod · 0.45
borrowMethod · 0.45

Tested by

no test coverage detected