pub struct Origins { /* private fields */ }Expand description
The pair of origins a custom protocol lives between, and the sole entry point for turning a webview request into one the server may serve.
Implementations§
Source§impl Origins
impl Origins
Sourcepub fn new(scheme: &str, platform: Platform) -> Result<Origins, OriginError>
pub fn new(scheme: &str, platform: Platform) -> Result<Origins, OriginError>
Builds the origin pair for a protocol named scheme on platform.
§Errors
OriginError::InvalidScheme if the name cannot serve as both a URL
scheme and a DNS label.
Sourcepub fn collides_with(&self, url: &str) -> bool
pub fn collides_with(&self, url: &str) -> bool
Whether url names the origin this protocol serves.
The shell uses this to refuse, at startup, an application whose public base URL is our own canonical origin: absolute URLs built from it would escape the protocol and be fetched for real, which is a broken image long after the mistake rather than an error at the moment of it.
Sourcepub fn accept<B>(&self, request: Request<B>) -> Outcome<B>
pub fn accept<B>(&self, request: Request<B>) -> Outcome<B>
Admits a request and rewrites it into the canonical origin.
Admission is only the question of address: a request naming somebody else’s origin is refused, and everything else is rewritten. Deciding whether a request may act is the server’s job, and this crate attaches no credential that would undermine the answer.
Origin and Referer are moved onto the canonical origin only when
they were ours to begin with. A foreign value passes through untouched,
so a server running its own origin checks still sees a stranger as a
stranger.
Host is set, because no webview reliably sends one and a server
comparing Origin against it needs both. Accept-Encoding is dropped,
because nothing here is on a wire and WKWebView will not decode what it
is handed anyway. Hop-by-hop headers
go too, including the ones a Connection names - except Host,
Origin and Referer, which a client does not get to delete.