mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 20:45:29 +00:00
Rename 'respond' to 'send_header'
This commit is contained in:
parent
a007908248
commit
0909a4def8
1 changed files with 7 additions and 7 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -100,12 +100,12 @@ async fn handle_request(stream: TcpStream) -> Result {
|
||||||
let url = match parse_request(stream).await {
|
let url = match parse_request(stream).await {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
Err((status, msg)) => {
|
Err((status, msg)) => {
|
||||||
respond(stream, &status.to_string(), &[&msg]).await?;
|
send_header(stream, &status.to_string(), &[&msg]).await?;
|
||||||
Err(msg)?
|
Err(msg)?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(e) = send_response(url, stream).await {
|
if let Err(e) = send_response(url, stream).await {
|
||||||
respond(stream, "51", &["Not found, sorry."]).await?;
|
send_header(stream, "51", &["Not found, sorry."]).await?;
|
||||||
Err(e)?
|
Err(e)?
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -194,7 +194,7 @@ async fn send_response<W: Write + Unpin>(url: Url, stream: &mut W) -> Result {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if client is not redirected, links may not work as expected without trailing slash
|
// if client is not redirected, links may not work as expected without trailing slash
|
||||||
return respond(stream, "31", &[url.as_str(), "/"]).await;
|
return send_header(stream, "31", &[url.as_str(), "/"]).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,7 +206,7 @@ async fn send_response<W: Write + Unpin>(url: Url, stream: &mut W) -> Result {
|
||||||
send_text_gemini_header(stream).await?;
|
send_text_gemini_header(stream).await?;
|
||||||
} else {
|
} else {
|
||||||
let mime = mime_guess::from_path(&path).first_or_octet_stream();
|
let mime = mime_guess::from_path(&path).first_or_octet_stream();
|
||||||
respond(stream, "20", &[mime.essence_str()]).await?;
|
send_header(stream, "20", &[mime.essence_str()]).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send body.
|
// Send body.
|
||||||
|
|
@ -214,7 +214,7 @@ async fn send_response<W: Write + Unpin>(url: Url, stream: &mut W) -> Result {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn respond<W: Write + Unpin>(stream: &mut W, status: &str, meta: &[&str]) -> Result {
|
async fn send_header<W: Write + Unpin>(stream: &mut W, status: &str, meta: &[&str]) -> Result {
|
||||||
log::info!("Responding with status {} and meta {:?}", status, meta);
|
log::info!("Responding with status {} and meta {:?}", status, meta);
|
||||||
stream.write_all(status.as_bytes()).await?;
|
stream.write_all(status.as_bytes()).await?;
|
||||||
stream.write_all(b" ").await?;
|
stream.write_all(b" ").await?;
|
||||||
|
|
@ -246,8 +246,8 @@ async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result
|
||||||
|
|
||||||
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() {
|
||||||
respond(stream, "20", &["text/gemini;lang=", lang]).await
|
send_header(stream, "20", &["text/gemini;lang=", lang]).await
|
||||||
} else {
|
} else {
|
||||||
respond(stream, "20", &["text/gemini"]).await
|
send_header(stream, "20", &["text/gemini"]).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue