Skip to main content

compmd_host/
refusal.rs

1//! Why the serving contract refuses a request ([hosting], decision 8), with the status that says it.
2//!
3//! [hosting]: https://github.com/comp-markdown/compmd/blob/main/docs/hosting.md
4
5use http::StatusCode;
6
7/// A refused request: its status, and why, which the answer says in plain text to any origin.
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub struct Refusal {
10    /// `404` or `405`.
11    pub status: StatusCode,
12    /// Why, in plain text.
13    pub why: &'static str,
14}
15
16impl Refusal {
17    /// A request that isn't for a file the host serves.
18    pub const NOT_SERVED: Self = Self {
19        status: StatusCode::NOT_FOUND,
20        why: "not a file of the frames or packs this host serves",
21    };
22
23    /// A request with another method than `GET`.
24    pub const ONLY_GET: Self = Self {
25        status: StatusCode::METHOD_NOT_ALLOWED,
26        why: "the frames and packs are only read, with GET",
27    };
28}