mirror of
https://github.com/bytedance/g3.git
synced 2026-05-05 23:41:57 +00:00
g3proxy: use no more error templates page
This commit is contained in:
parent
216e392fe1
commit
0840ae6d36
4 changed files with 11 additions and 103 deletions
79
Cargo.lock
generated
79
Cargo.lock
generated
|
|
@ -132,41 +132,6 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16"
|
||||
|
||||
[[package]]
|
||||
name = "askama"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47cbc3cf73fa8d9833727bbee4835ba5c421a0d65b72daf9a7b5d0e0f9cfb57e"
|
||||
dependencies = [
|
||||
"askama_derive",
|
||||
"askama_escape",
|
||||
"humansize",
|
||||
"num-traits",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "askama_derive"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c22fbe0413545c098358e56966ff22cdd039e10215ae213cfbd65032b119fc94"
|
||||
dependencies = [
|
||||
"basic-toml",
|
||||
"mime",
|
||||
"mime_guess",
|
||||
"nom",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"syn 2.0.26",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "askama_escape"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
|
||||
|
||||
[[package]]
|
||||
name = "async-recursion"
|
||||
version = "1.0.4"
|
||||
|
|
@ -231,15 +196,6 @@ version = "0.21.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"
|
||||
|
||||
[[package]]
|
||||
name = "basic-toml"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7bfc506e7a2370ec239e1d072507b2a80c833083699d3c6fa176fbb4de8448c6"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
|
|
@ -1426,7 +1382,6 @@ dependencies = [
|
|||
"anyhow",
|
||||
"arc-swap",
|
||||
"ascii",
|
||||
"askama",
|
||||
"async-recursion",
|
||||
"async-trait",
|
||||
"base64",
|
||||
|
|
@ -1780,15 +1735,6 @@ version = "0.1.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "016b02deb8b0c415d8d56a6f0ab265e50c22df61194e37f9be75ed3a722de8a6"
|
||||
|
||||
[[package]]
|
||||
name = "humansize"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
|
||||
dependencies = [
|
||||
"libm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.57"
|
||||
|
|
@ -1973,12 +1919,6 @@ version = "0.2.147"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "libm"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4"
|
||||
|
||||
[[package]]
|
||||
name = "libsystemd"
|
||||
version = "0.6.0"
|
||||
|
|
@ -2096,16 +2036,6 @@ version = "0.3.17"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "mime_guess"
|
||||
version = "2.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
|
||||
dependencies = [
|
||||
"mime",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
|
|
@ -3305,15 +3235,6 @@ version = "1.16.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ url.workspace = true
|
|||
http.workspace = true
|
||||
h2.workspace = true
|
||||
mime.workspace = true
|
||||
askama = "0.12"
|
||||
serde_json.workspace = true
|
||||
ip_network.workspace = true
|
||||
ip_network_table.workspace = true
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use std::io::{self, Write};
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
use ascii::AsciiStr;
|
||||
use askama::Template;
|
||||
use http::{StatusCode, Version};
|
||||
use mime::Mime;
|
||||
use tokio::io::{AsyncWrite, AsyncWriteExt, BufWriter};
|
||||
|
|
@ -31,13 +30,6 @@ use crate::module::http_header;
|
|||
use crate::module::tcp_connect::TcpConnectError;
|
||||
use crate::serve::ServerTaskError;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "error.html")]
|
||||
struct ErrorPageTemplate<'a> {
|
||||
code: u16,
|
||||
reason: &'a str,
|
||||
}
|
||||
|
||||
struct CustomStatusCode {}
|
||||
|
||||
impl CustomStatusCode {
|
||||
|
|
@ -525,21 +517,23 @@ impl HttpProxyClientResponse {
|
|||
{
|
||||
let mut writer = BufWriter::new(writer);
|
||||
|
||||
let error = ErrorPageTemplate {
|
||||
code: self.status.as_u16(),
|
||||
reason: self.canonical_reason(),
|
||||
};
|
||||
let body = error
|
||||
.render()
|
||||
.map_or_else(|e| format!("unable to render http body: {e}"), |v| v);
|
||||
let code = self.status.as_u16();
|
||||
let reason = self.canonical_reason();
|
||||
let body = format!(
|
||||
"<html>\n\
|
||||
<head><title>{code} {reason}</title></head>\n\
|
||||
<body>\n\
|
||||
<div style=\"text-align: center;\"><h1>{code} {reason}</h1></div>\n\
|
||||
</body>\n\
|
||||
</html>\n"
|
||||
);
|
||||
|
||||
let mut header = Vec::<u8>::with_capacity(Self::RESPONSE_BUFFER_SIZE);
|
||||
write!(
|
||||
header,
|
||||
"{:?} {} {}\r\n",
|
||||
"{:?} {} {reason}\r\n",
|
||||
self.version,
|
||||
self.status.as_str(),
|
||||
error.reason,
|
||||
)?;
|
||||
for line in &self.extra_headers {
|
||||
header.extend_from_slice(line.as_bytes());
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
<html>
|
||||
<head><title>{{ code }} {{ reason }}</title></head>
|
||||
<body>
|
||||
<div style="text-align: center;"><h1>{{ code }} {{ reason }}</h1></div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue