aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 2 insertions, 33 deletions
diff --git a/src/main.rs b/src/main.rs
index 8514b29..e8869c7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,6 +13,7 @@ use hyper::service::{make_service_fn, service_fn};
use hyper::Method;
use hyper::StatusCode;
use hyper::{Body, Server};
+use origins::HttpOrigin;
use percent_encoding::percent_decode_str;
use pulldown_cmark::html;
use pulldown_cmark::Options;
@@ -27,9 +28,7 @@ use std::env;
use std::path::Component;
use std::path::Path;
use std::path::PathBuf;
-use std::str::FromStr;
use std::sync::Arc;
-use url::Url;
#[cfg(unix)]
use {
@@ -46,6 +45,7 @@ mod diff;
mod error;
mod forms;
mod get_routes;
+mod origins;
mod post_routes;
mod shares;
@@ -115,37 +115,6 @@ async fn main() {
}
}
-#[derive(Clone, Debug)]
-struct HttpOrigin {
- origin: String,
- host_idx: usize,
-}
-
-impl HttpOrigin {
- /// Returns the Host header value (e.g. `example.com` for the origin `https://example.com`).
- fn host(&self) -> &str {
- &self.origin[self.host_idx..]
- }
-}
-
-impl FromStr for HttpOrigin {
- type Err = &'static str;
-
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- let url = Url::parse(s).map_err(|_| "invalid URL")?;
- if url.scheme() != "http" && url.scheme() != "https" {
- return Err("expected http:// or https:// scheme");
- }
- if url.path() != "/" {
- return Err("path must be /".into());
- }
- Ok(HttpOrigin {
- origin: url.origin().ascii_serialization(),
- host_idx: url.scheme().len() + "://".len(),
- })
- }
-}
-
async fn serve<C: Controller + Send + Sync + 'static>(controller: C, args: Args) {
let controller = Arc::new(controller);