Compare commits

..

1 Commits

Author SHA1 Message Date
Brian Picciano
16c1d0c4aa WIP 2023-07-27 18:00:23 +02:00
5 changed files with 24 additions and 53 deletions

View File

@ -35,12 +35,6 @@ impl Certificate {
.set_subject_name(&name)
.or_unexpected_while("setting subject name")?;
// 1970/01/01
let not_before = Asn1Time::from_unix(0).expect("initializing not_before");
builder
.set_not_before(not_before.as_ref())
.or_unexpected_while("setting not_before")?;
// 9999/07/23
let not_after = Asn1Time::from_unix(253388296800).expect("initializing not_after");
builder

View File

@ -3,32 +3,3 @@ pub mod gemini;
pub mod http;
pub use config::*;
use std::borrow;
fn append_index_to_path<'path, 'index>(
path: &'path str,
index: &'index str,
) -> borrow::Cow<'path, str> {
if path.len() == 0 {
let mut path = String::with_capacity(1 + index.len());
path.push('/');
path.push_str(index);
return borrow::Cow::Owned(path);
}
if path.ends_with('/') {
let mut indexed_path = String::with_capacity(path.len() + index.len());
indexed_path.push_str(path.as_ref());
indexed_path.push_str(index);
return borrow::Cow::Owned(indexed_path);
}
borrow::Cow::Borrowed(path)
}
fn guess_mime(path: &str) -> String {
mime_guess::from_path(path)
.first_or_octet_stream()
.to_string()
}

View File

@ -88,22 +88,14 @@ impl Service {
.into_gemini_request()
.map_err(|e| HandleConnError::ClientError(format!("failed to parse request: {e}")))?;
let path = service::append_index_to_path(req.path(), "index.gmi");
let f = match self.domain_manager.get_file(domain, &path) {
let f = match self.domain_manager.get_file(domain, req.path()) {
Ok(f) => f,
Err(domain::manager::GetFileError::DomainNotFound) => panic!("TODO"),
Err(domain::manager::GetFileError::FileNotFound) => {
return Ok(self.respond_conn(w, "51", "File not found", None).await?)
}
Err(domain::manager::GetFileError::FileNotFound) => panic!("TODO"),
Err(domain::manager::GetFileError::Unexpected(e)) => return Err(e.into()),
};
let content_type = service::guess_mime(&path);
Ok(self
.respond_conn(w, "20", content_type.as_str(), Some(f))
.await?)
Ok(self.respond_conn(w, "20", "TODO", Some(f)).await?)
}
async fn proxy_conn<IO>(

View File

@ -79,9 +79,13 @@ struct DomainSyncArgs {
impl<'svc> Service {
fn serve(&self, status_code: u16, path: &str, body: Body) -> Response<Body> {
let content_type = mime_guess::from_path(path)
.first_or_octet_stream()
.to_string();
match Response::builder()
.status(status_code)
.header("Content-Type", service::guess_mime(path))
.header("Content-Type", content_type)
.body(body)
{
Ok(res) => res,
@ -157,10 +161,20 @@ impl<'svc> Service {
}
async fn serve_origin(&self, domain: domain::Name, req: Request<Body>) -> Response<Body> {
let path = service::append_index_to_path(req.uri().path(), "index.html");
let mut path_owned;
let path = req.uri().path();
match self.domain_manager.get_file(&domain, &path) {
Ok(f) => self.serve(200, &path, Body::wrap_stream(f)),
let path = match path.ends_with('/') {
true => {
path_owned = String::from(path);
path_owned.push_str("index.html");
path_owned.as_str()
}
false => path,
};
match self.domain_manager.get_file(&domain, path) {
Ok(f) => self.serve(200, path, Body::wrap_stream(f)),
Err(domain::manager::GetFileError::DomainNotFound) => {
return self.render_error_page(404, "Domain not found")
}

View File

@ -2,8 +2,8 @@
This is the gemini index.
=> /foo.gmi foo
=> foo /foo.gmi
=> /subdir/bar.gmi bar
=> bar /subdir/bar.gmi
=> /penguin.jpg penguin
=> penguin /penguin.jpg