0.34.6_repo_cleanup
This commit is contained in:
1 parent
ce1a90397c
commit
133d2f0f91
273 files changed
+5969
-6926
No files matched your search
+33
-11
@@ -1,5 +1,3 @@
|
||||
// Shared immutable precompressed responses for private panel HTML and assets.
|
||||
// Each embedded document is encoded once on first request, never per visitor.
|
||||
use crate::settings::PanelCompression;
|
||||
use axum::{body::Body, response::Response};
|
||||
use bytes::Bytes;
|
||||
@@ -22,16 +20,31 @@ impl PanelContent {
|
||||
let mut br = Vec::new();
|
||||
{
|
||||
let mut writer = brotli::CompressorWriter::new(&mut br, 4096, 5, 22);
|
||||
writer.write_all(raw.as_bytes()).expect("compress panel Brotli");
|
||||
writer
|
||||
.write_all(raw.as_bytes())
|
||||
.expect("compress panel Brotli");
|
||||
}
|
||||
let zstd = zstd::stream::encode_all(raw.as_bytes(), 3).expect("compress panel zstd");
|
||||
Self { plain: Bytes::from_static(raw.as_bytes()), gzip, brotli: Bytes::from(br), zstd: Bytes::from(zstd) }
|
||||
Self {
|
||||
plain: Bytes::from_static(raw.as_bytes()),
|
||||
gzip,
|
||||
brotli: Bytes::from(br),
|
||||
zstd: Bytes::from(zstd),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn response(&self, headers: &HeaderMap, codecs: &PanelCompression, mime: &'static str) -> Response {
|
||||
pub(super) fn response(
|
||||
&self,
|
||||
headers: &HeaderMap,
|
||||
codecs: &PanelCompression,
|
||||
mime: &'static str,
|
||||
) -> Response {
|
||||
let settings = crate::compression::Settings {
|
||||
gzip: codecs.gzip, br: codecs.br, zstd: codecs.zstd,
|
||||
deflate: false, min_bytes: 1024,
|
||||
gzip: codecs.gzip,
|
||||
br: codecs.br,
|
||||
zstd: codecs.zstd,
|
||||
deflate: false,
|
||||
min_bytes: 1024,
|
||||
};
|
||||
let encoding = if crate::compression::no_transform(headers) {
|
||||
None
|
||||
@@ -45,12 +58,21 @@ impl PanelContent {
|
||||
_ => (self.plain.clone(), None),
|
||||
};
|
||||
let mut response = Response::new(Body::from(body.clone()));
|
||||
response.headers_mut().insert(header::CONTENT_TYPE, HeaderValue::from_static(mime));
|
||||
response.headers_mut().insert(header::CONTENT_LENGTH, HeaderValue::from_str(&body.len().to_string()).expect("valid length"));
|
||||
response
|
||||
.headers_mut()
|
||||
.insert(header::CONTENT_TYPE, HeaderValue::from_static(mime));
|
||||
response.headers_mut().insert(
|
||||
header::CONTENT_LENGTH,
|
||||
HeaderValue::from_str(&body.len().to_string()).expect("valid length"),
|
||||
);
|
||||
if let Some(name) = name {
|
||||
response.headers_mut().insert(header::CONTENT_ENCODING, HeaderValue::from_static(name));
|
||||
response
|
||||
.headers_mut()
|
||||
.insert(header::CONTENT_ENCODING, HeaderValue::from_static(name));
|
||||
}
|
||||
response.headers_mut().insert(header::VARY, HeaderValue::from_static("Accept-Encoding"));
|
||||
response
|
||||
.headers_mut()
|
||||
.insert(header::VARY, HeaderValue::from_static("Accept-Encoding"));
|
||||
response
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user