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

Function http_post

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

Source from the content-addressed store, hash-verified

160}
161
162fn http_post<'gc>(
163 ctx: &mut crate::vm::State<'gc>,
164 args: Vec<Value<'gc>>,
165) -> Result<Value<'gc>, VmError> {
166 if args.len() < 2 {
167 return Err(VmError::RuntimeError(
168 "URL and body required for POST request".into(),
169 ));
170 }
171
172 let url = args[0].as_string()?.to_string();
173 let body = args[1].as_string()?.to_string();
174 let headers_map = if args.len() > 2 {
175 if let Value::Object(obj) = args[2] {
176 let borrowed = obj.borrow();
177 parse_headers(borrowed.fields.clone())
178 } else {
179 return Err(VmError::RuntimeError("Headers must be an object".into()));
180 }
181 } else {
182 HeaderMap::new()
183 };
184
185 let result = Handle::current().block_on(async {
186 let response = make_request(reqwest::Method::POST, &url, headers_map, Some(body))
187 .await
188 .map_err(|e| VmError::RuntimeError(format!("HTTP request failed: {}", e)))?;
189
190 response_to_object(ctx.get_context(), response).await
191 })?;
192
193 Ok(result)
194}
195
196fn http_put<'gc>(
197 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
borrowMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected