mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-09 13:05:29 +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(())
|
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 {
|
async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result {
|
||||||
// https://url.spec.whatwg.org/#path-percent-encode-set
|
// https://url.spec.whatwg.org/#path-percent-encode-set
|
||||||
const ENCODE_SET: AsciiSet = CONTROLS.add(b' ')
|
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(())
|
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 {
|
async fn send_text_gemini_header<W: Write + Unpin>(stream: &mut W) -> Result {
|
||||||
if let Some(lang) = ARGS.language.as_deref() {
|
if let Some(lang) = ARGS.language.as_deref() {
|
||||||
send_header(stream, 20, &["text/gemini;lang=", lang]).await
|
send_header(stream, 20, &["text/gemini;lang=", lang]).await
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue