Reorganize some code

This commit is contained in:
Matt Brubeck 2020-12-31 15:41:15 -08:00
parent 879422c2cc
commit 847434d844

View file

@ -226,17 +226,6 @@ async fn send_response<W: Write + Unpin>(url: Url, stream: &mut W) -> Result {
Ok(())
}
async fn send_header<W: Write + Unpin>(stream: &mut W, status: u8, meta: &[&str]) -> Result {
use std::fmt::Write;
let mut response = String::with_capacity(64);
write!(response, "{} ", status)?;
response.extend(meta.iter().copied());
log::info!("Responding with status {:?}", response);
response.push_str("\r\n");
stream.write_all(response.as_bytes()).await?;
Ok(())
}
async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result {
// https://url.spec.whatwg.org/#path-percent-encode-set
const ENCODE_SET: AsciiSet = CONTROLS.add(b' ')
@ -269,6 +258,17 @@ async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result
Ok(())
}
async fn send_header<W: Write + Unpin>(stream: &mut W, status: u8, meta: &[&str]) -> Result {
use std::fmt::Write;
let mut response = String::with_capacity(64);
write!(response, "{} ", status)?;
response.extend(meta.iter().copied());
log::info!("Responding with status {:?}", response);
response.push_str("\r\n");
stream.write_all(response.as_bytes()).await?;
Ok(())
}
async fn send_text_gemini_header<W: Write + Unpin>(stream: &mut W) -> Result {
if let Some(lang) = ARGS.language.as_deref() {
send_header(stream, 20, &["text/gemini;lang=", lang]).await