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

Function temporary_redirect

aiscript-vm/src/builtins/response.rs:88–120  ·  view source on GitHub ↗

Creates a temporary redirect (307) response with the specified target URL Usage: temporary_redirect(target="/new-url")

(
    state: &mut State<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

86/// Creates a temporary redirect (307) response with the specified target URL
87/// Usage: temporary_redirect(target="/new-url")
88pub fn temporary_redirect<'gc>(
89 state: &mut State<'gc>,
90 args: Vec<Value<'gc>>,
91) -> Result<Value<'gc>, VmError> {
92 if args.len() != 2 || !matches!(args[0], Value::String(_)) {
93 return Err(VmError::RuntimeError(
94 "temporary_redirect() requires a target URL as keyword argument (e.g., temporary_redirect(target=\"/new-url\"))".into()
95 ));
96 }
97
98 if args[0].as_string()?.to_str().unwrap() != "target" {
99 return Err(VmError::RuntimeError(
100 "temporary_redirect() requires 'target' keyword argument".into(),
101 ));
102 }
103
104 let target = args[1].as_string()?;
105
106 // Create headers with Location set
107 let fields = [(state.intern(b"Location"), Value::String(target))]
108 .into_iter()
109 .collect();
110 // Create response with 307 status code
111 let args = [
112 Value::String(state.intern(b"status_code")),
113 Value::Number(307.0),
114 Value::String(state.intern(b"headers")),
115 Value::Object(Gc::new(state, RefLock::new(Object { fields }))),
116 ]
117 .into_iter()
118 .collect();
119 response(state, args)
120}
121
122/// Creates a permanent redirect (308) response with the specified target URL
123/// Usage: permanent_redirect(target="/new-url")

Callers

nothing calls this directly

Calls 7

RuntimeErrorClass · 0.85
ObjectClass · 0.85
responseFunction · 0.85
lenMethod · 0.80
to_strMethod · 0.80
as_stringMethod · 0.80
internMethod · 0.45

Tested by

no test coverage detected