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

Function http_head

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

Source from the content-addressed store, hash-verified

297}
298
299fn http_head<'gc>(
300 ctx: &mut crate::vm::State<'gc>,
301 args: Vec<Value<'gc>>,
302) -> Result<Value<'gc>, VmError> {
303 if args.is_empty() {
304 return Err(VmError::RuntimeError(
305 "URL required for HEAD request".into(),
306 ));
307 }
308
309 let url = args[0].as_string()?.to_string();
310 let headers = if args.len() > 1 {
311 if let Value::Object(obj) = args[1] {
312 obj.borrow().fields.clone()
313 } else {
314 return Err(VmError::RuntimeError("Headers must be an object".into()));
315 }
316 } else {
317 HashMap::default()
318 };
319
320 let headers_map = parse_headers(headers);
321
322 let result = Handle::current().block_on(async {
323 let response = make_request(reqwest::Method::HEAD, &url, headers_map, None)
324 .await
325 .map_err(|e| VmError::RuntimeError(format!("HTTP request failed: {}", e)))?;
326
327 response_to_object(ctx.get_context(), response).await
328 })?;
329
330 Ok(result)
331}

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected