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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#[macro_export]
macro_rules! static_resources_initializer {
( $($name:expr => $path:expr), * $(,)* ) => {
{
$crate::StaticResponse::fairing(|resources| {
$crate::static_resources_initialize!(
resources
$(, $name => $path)*
);
})
}
};
}
#[macro_export]
macro_rules! static_response_handler {
( $($route:expr => $handler_name:ident => $name:expr), * $(,)* ) => {
$(
#[get($route)]
fn $handler_name(
static_resources: &$crate::rocket::State<$crate::StaticContextManager>,
etag_if_none_match: $crate::EtagIfNoneMatch,
) -> $crate::StaticResponse {
static_resources.build(&etag_if_none_match, $name)
}
)*
};
}
#[cfg(feature = "cache")]
#[macro_export]
macro_rules! cached_static_response_handler {
( $max_age:expr, $must_revalidate:expr ; $($route:expr => $handler_name:ident => $name:expr), * $(,)* ) => {
$(
#[get($route)]
fn $handler_name(
static_resources: &$crate::rocket::State<$crate::StaticContextManager>,
etag_if_none_match: $crate::EtagIfNoneMatch,
) -> $crate::CacheResponse<$crate::StaticResponse> {
let responder = static_resources.build(&etag_if_none_match, $name);
$crate::CacheResponse::public_only_release(responder, $max_age, $must_revalidate)
}
)*
};
( $max_age:expr ; $($route:expr => $handler_name:ident => $name:expr), * $(,)* ) => {
$crate::cached_static_response_handler! {
$max_age, false;
$(
$route => $handler_name => $name,
)*
}
};
}