mirror of
https://github.com/samsonjs/agate.git
synced 2026-03-26 09:15:53 +00:00
Option to add a language code to text/gemini responses
This commit is contained in:
parent
dfa5dbd971
commit
7a117f3a47
2 changed files with 10 additions and 2 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue