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

Function permanent_redirect

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

Creates a permanent redirect (308) response with the specified target URL Usage: permanent_redirect(target="/new-url")

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

Source from the content-addressed store, hash-verified

122/// Creates a permanent redirect (308) response with the specified target URL
123/// Usage: permanent_redirect(target="/new-url")
124pub fn permanent_redirect<'gc>(
125 state: &mut State<'gc>,
126 args: Vec<Value<'gc>>,
127) -> Result<Value<'gc>, VmError> {
128 if args.len() != 2 || !matches!(args[0], Value::String(_)) {
129 return Err(VmError::RuntimeError(
130 "permanent_redirect() requires a target URL as keyword argument (e.g., permanent_redirect(target=\"/new-url\"))".into()
131 ));
132 }
133
134 if args[0].as_string()?.to_str().unwrap() != "target" {
135 return Err(VmError::RuntimeError(
136 "permanent_redirect() requires 'target' keyword argument".into(),
137 ));
138 }
139
140 let target = args[1].as_string()?;
141
142 // Create headers with Location set
143 let fields = [(state.intern(b"Location"), Value::String(target))]
144 .into_iter()
145 .collect();
146
147 // Create response with 308 status code
148 let args = [
149 Value::String(state.intern(b"status_code")),
150 Value::Number(308.0),
151 Value::String(state.intern(b"headers")),
152 Value::Object(Gc::new(state, RefLock::new(Object { fields }))),
153 ]
154 .into_iter()
155 .collect();
156
157 response(state, args)
158}

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