MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / http_get

Function http_get

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

Source from the content-addressed store, hash-verified

128}
129
130fn 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
162fn http_post<'gc>(
163 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
as_stringMethod · 0.80
lenMethod · 0.80
get_contextMethod · 0.80
borrowMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected