~int80h/gemserv

Change how the default value for config.server[].index is handled v1 PROPOSED

Nick Thomas: 2
 Change how the default value for config.server[].index is handled
 Change how the default value for config.server[].index is handled

 4 files changed, 22 insertions(+), 18 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~int80h/gemserv/patches/40566/mbox | git am -3
Learn more about email & git

[PATCH] Change how the default value for config.server[].index is handled Export this patch

The `handle_connection` function is long and scary; this is an easy
thing to remove from it, essentially turning code into data.
---
 src/con_handler.rs | 5 -----
 src/config.rs      | 6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/con_handler.rs b/src/con_handler.rs
index 6d6c83f..eff7259 100644
--- a/src/con_handler.rs
+++ b/src/con_handler.rs
@@ -155,11 +155,6 @@ async fn handle_cgi(

// TODO Rewrite this monster.
pub async fn handle_connection(mut con: conn::Connection, url: url::Url) -> Result {
    let index = match &con.srv.server.index {
        Some(i) => i.clone(),
        None => "index.gemini".to_string(),
    };

    match &con.srv.server.redirect.to_owned() {
        Some(re) => {
            let u = match url.path() {
diff --git a/src/config.rs b/src/config.rs
index 0f83cf3..b888d08 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -73,6 +73,12 @@ impl Config {
            Err(e) => return Err(Box::new(e)),
        };

        for srv in config.server.iter_mut() {
            if srv.index.is_none() {
                srv.index = Some("index.gemini".to_owned());
            }
        }

        if config.host.is_some() || config.port.is_some() {
            eprintln!(
                "The host/port keys are depricated in favor \
-- 
2.39.2

[PATCH v2] Change how the default value for config.server[].index is handled Export this patch

The `handle_connection` function is long and scary; this is an easy
thing to remove from it, essentially turning code into data.

v1 of this patch missed a hunk and didn't even compile :S.
---
 src/con_handler.rs | 23 ++++++++++-------------
 src/config.rs      |  6 ++++++
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/con_handler.rs b/src/con_handler.rs
index 6d6c83f..27f15fa 100644
--- a/src/con_handler.rs
+++ b/src/con_handler.rs
@@ -155,11 +155,6 @@ async fn handle_cgi(

// TODO Rewrite this monster.
pub async fn handle_connection(mut con: conn::Connection, url: url::Url) -> Result {
    let index = match &con.srv.server.index {
        Some(i) => i.clone(),
        None => "index.gemini".to_string(),
    };

    match &con.srv.server.redirect.to_owned() {
        Some(re) => {
            let u = match url.path() {
@@ -308,16 +303,18 @@ pub async fn handle_connection(mut con: conn::Connection, url: url::Url) -> Resu
            .await?;
            return Ok(());
        }
        if path.join(&index).exists() {
            path.push(index);
            meta = tokio::fs::metadata(&path).await?;
            perm = meta.permissions();
            if perm.mode() & 0o0444 != 0o444 {
                let mut p = path.clone();
                p.pop();
                path.push(format!("{}/", p.display()));
        if let Some(index) = &con.srv.server.index {
            if path.join(&index).exists() {
                path.push(index);
                meta = tokio::fs::metadata(&path).await?;
                perm = meta.permissions();
                if perm.mode() & 0o0444 != 0o444 {
                    let mut p = path.clone();
                    p.pop();
                    path.push(format!("{}/", p.display()));
                    meta = tokio::fs::metadata(&path).await?;
                    perm = meta.permissions();
                }
            }
        }
    }
diff --git a/src/config.rs b/src/config.rs
index 0f83cf3..b888d08 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -73,6 +73,12 @@ impl Config {
            Err(e) => return Err(Box::new(e)),
        };

        for srv in config.server.iter_mut() {
            if srv.index.is_none() {
                srv.index = Some("index.gemini".to_owned());
            }
        }

        if config.host.is_some() || config.port.is_some() {
            eprintln!(
                "The host/port keys are depricated in favor \
-- 
2.39.2