///|
/// Whether a request comes to the address of the server and from its own pages.
#derive(Eq, Debug)
pub(all) enum SiteDecision {
/// The server can continue with the request.
SameSite
/// The request has no `Host`, or the `Host` is not the address of the server.
/// A name that points to the local machine gives this case.
OtherHost
/// The `Origin` is not the origin of the server. A page of another site gives
/// this case.
OtherOrigin
}
///|
/// Checks the `Host` and the `Origin` header of a request to the server on a
/// port. `None` is an absent header.
///
/// The only host is `127.0.0.1:` and the only origin is
/// `http://127.0.0.1:`, with the exact text. An absent origin is accepted,
/// because a browser does not send it for a page that the user opens. The host
/// is checked first. A browser leaves out the port 80, so a server on that port
/// refuses its requests.
pub fn site_decision(
port : Port,
host~ : String?,
origin~ : String?,
) -> SiteDecision {
let address = "127.0.0.1:\{port.to_int()}"
guard host == Some(address) else { return OtherHost }
guard origin is None || origin == Some("http://\{address}") else {
return OtherOrigin
}
SameSite
}
///|
pub extend SiteDecision with Eq::{not_equal, equal}
///|
pub extend SiteDecision with @debug.Debug::{to_repr}