Http module

expect_redirect

procedureextensionexperimentalSource

The response redirects (3xx, or exactly status when given) to location.

Example
go_home :: () -> Response {
    return redirect("/home");
}

main :: () {
    app: App;
    defer free_app(*app);

    get(*app, "/", go_home);

    api := test_client(*app);

    response, _ := get(api, "/");
    defer close(*response);

    assert(expect_redirect(response, "/home", 302));
}

Doesn't run in the browser (skipped on wasm).

expect_redirect :: (
    response: Client_Response,
    location: string,
    status := 0,
    loc := #caller_location
) -> bool

The response redirects (3xx, or exactly status when given) to location.

Parameters

response: Client_Response
location: string
the Location the response must have.
status := 0
the exact status wanted. 0 accepts any 3xx.
loc := #caller_location

Returns

bool
Example
go_home :: () -> Response {
    return redirect("/home");
}

main :: () {
    app: App;
    defer free_app(*app);

    get(*app, "/", go_home);

    api := test_client(*app);

    response, _ := get(api, "/");
    defer close(*response);

    assert(expect_redirect(response, "/home", 302));
}

Doesn't run in the browser (skipped on wasm).

See also