1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/// Mountpoint is the path on which the wasm file is mounted.
///
/// If in FASTN.ftd, we have:
///
/// ```ftd
/// -- import: fastn
/// -- fastn.package: hello-world
/// -- fastn.url-mappings:
/// /foo/* -> wasm+proxy://hello-world.wasm/*
/// ```
///
/// Then the `mountpoint` is `/foo/`.
///
/// Implementation note: The `mountpoint` is passed by the host using `x-fastn-mountpoint` header.
pub struct Mountpoint(pub String);

impl ft_sdk::FromRequest for Mountpoint {
    fn from_request(req: &http::Request<serde_json::Value>) -> Result<Mountpoint, ft_sdk::Error> {
        // we are unwrapping because this header must always be present.
        Ok(Self(
            req.headers()
                .get("x-fastn-mountpoint")
                .unwrap()
                .to_str()
                .unwrap()
                .to_string(),
        ))
    }
}