mirror of
https://github.com/samsonjs/agate.git
synced 2026-03-25 09:05:50 +00:00
Reorganize some code
This commit is contained in:
parent
879422c2cc
commit
847434d844
1 changed files with 11 additions and 11 deletions
22
src/main.rs
22
src/main.rs
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue