agate

Simple gemini server for static files
git clone https://github.com/mbrubeck/agate.git
Log | Files | Refs | README

commit 7a117f3a470478bdd0464a6abea5be3c47efc877
parent dfa5dbd9717bef356b532cb1525d412e02c04076
Author: Matt Brubeck <mbrubeck@limpet.net>
Date:   Tue, 22 Dec 2020 16:16:42 -0800

Option to add a language code to text/gemini responses

Diffstat:
MREADME.md | 3++-
Msrc/main.rs | 9++++++++-
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -27,7 +27,7 @@ openssl req -x509 -newkey rsa:4096 -keyout key.rsa -out cert.pem \ -days 3650 -nodes -subj "/CN=example.com" ``` -3. Run the server. You can use the following arguments to specify the locations of the content directory, certificate and key files, IP address and port to listen on, and (optionally) a domain that will be used to validate request URLs: +3. Run the server. You can use the following arguments to specify the locations of the content directory, certificate and key files, IP address and port to listen on, host name to expect in request URLs, and default language code(s) to include in the MIME type for for text/gemini files: ``` agate --content path/to/content/ \ @@ -35,6 +35,7 @@ agate --content path/to/content/ \ --cert cert.pem \ --addr 0.0.0.0:1965 \ --hostname example.com + --lang en-US ``` All of the command-line arguments are optional. Run `agate --help` to see the default values used when arguments are omitted. diff --git a/src/main.rs b/src/main.rs @@ -45,6 +45,7 @@ struct Args { cert_file: String, key_file: String, hostname: Option<Host>, + language: Option<String>, } fn args() -> Result<Args> { @@ -55,6 +56,7 @@ fn args() -> Result<Args> { opts.optopt("", "key", "PKCS8 private key file (default ./key.rsa)", "FILE"); opts.optopt("", "addr", "Address to listen on (default 0.0.0.0:1965)", "IP:PORT"); opts.optopt("", "hostname", "Domain name of this Gemini server (optional)", "NAME"); + opts.optopt("", "lang", "RFC 4646 Language code(s) for text/gemini documents", "LANG"); opts.optflag("h", "help", "print this help menu"); let usage = opts.usage(&format!("Usage: {} FILE [options]", &args[0])); @@ -71,6 +73,7 @@ fn args() -> Result<Args> { content_dir: check_path(matches.opt_get_default("content", "content".into())?)?, cert_file: check_path(matches.opt_get_default("cert", "cert.pem".into())?)?, key_file: check_path(matches.opt_get_default("key", "key.rsa".into())?)?, + language: matches.opt_str("lang"), hostname, }) } @@ -191,7 +194,11 @@ async fn send_response<W: Write + Unpin>(url: Url, stream: &mut W) -> Result { // Send header. if path.extension() == Some(OsStr::new("gmi")) { - respond(stream, "20", &["text/gemini"]).await?; + if let Some(lang) = ARGS.language.as_deref() { + respond(stream, "20", &["text/gemini;lang=", lang]).await?; + } else { + respond(stream, "20", &["text/gemini"]).await?; + } } else { let mime = mime_guess::from_path(&path).first_or_octet_stream(); respond(stream, "20", &[mime.essence_str()]).await?;