mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 00:59:02 +03:00
feat: base64 index-data to avoid misencoding (#421)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::{args::Args, server::Response, utils::unix_now};
|
||||
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use base64::{engine::general_purpose::STANDARD, Engine as _};
|
||||
use headers::HeaderValue;
|
||||
use hyper::{header::WWW_AUTHENTICATE, Method};
|
||||
use indexmap::IndexMap;
|
||||
@@ -287,7 +287,7 @@ pub fn www_authenticate(res: &mut Response, args: &Args) -> Result<()> {
|
||||
|
||||
pub fn get_auth_user(authorization: &HeaderValue) -> Option<String> {
|
||||
if let Some(value) = strip_prefix(authorization.as_bytes(), b"Basic ") {
|
||||
let value: Vec<u8> = general_purpose::STANDARD.decode(value).ok()?;
|
||||
let value: Vec<u8> = STANDARD.decode(value).ok()?;
|
||||
let parts: Vec<&str> = std::str::from_utf8(&value).ok()?.split(':').collect();
|
||||
Some(parts[0].to_string())
|
||||
} else if let Some(value) = strip_prefix(authorization.as_bytes(), b"Digest ") {
|
||||
@@ -306,7 +306,7 @@ pub fn check_auth(
|
||||
auth_pass: &str,
|
||||
) -> Option<()> {
|
||||
if let Some(value) = strip_prefix(authorization.as_bytes(), b"Basic ") {
|
||||
let value: Vec<u8> = general_purpose::STANDARD.decode(value).ok()?;
|
||||
let value: Vec<u8> = STANDARD.decode(value).ok()?;
|
||||
let parts: Vec<&str> = std::str::from_utf8(&value).ok()?.split(':').collect();
|
||||
|
||||
if parts[0] != auth_user {
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::Args;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_zip::{tokio::write::ZipFileWriter, Compression, ZipDateTime, ZipEntryBuilder};
|
||||
use base64::{engine::general_purpose::STANDARD, Engine as _};
|
||||
use bytes::Bytes;
|
||||
use chrono::{LocalResult, TimeZone, Utc};
|
||||
use futures_util::{pin_mut, TryStreamExt};
|
||||
@@ -931,13 +932,14 @@ impl Server {
|
||||
};
|
||||
res.headers_mut()
|
||||
.typed_insert(ContentType::from(mime_guess::mime::TEXT_HTML_UTF_8));
|
||||
let index_data = STANDARD.encode(serde_json::to_string(&data)?);
|
||||
let output = self
|
||||
.html
|
||||
.replace(
|
||||
"__ASSETS_PREFIX__",
|
||||
&format!("{}{}", self.args.uri_prefix, self.assets_prefix),
|
||||
)
|
||||
.replace("__INDEX_DATA__", &serde_json::to_string(&data)?);
|
||||
.replace("__INDEX_DATA__", &index_data);
|
||||
res.headers_mut()
|
||||
.typed_insert(ContentLength(output.as_bytes().len() as u64));
|
||||
if head_only {
|
||||
@@ -1179,12 +1181,14 @@ impl Server {
|
||||
} else {
|
||||
res.headers_mut()
|
||||
.typed_insert(ContentType::from(mime_guess::mime::TEXT_HTML_UTF_8));
|
||||
|
||||
let index_data = STANDARD.encode(serde_json::to_string(&data)?);
|
||||
self.html
|
||||
.replace(
|
||||
"__ASSETS_PREFIX__",
|
||||
&format!("{}{}", self.args.uri_prefix, self.assets_prefix),
|
||||
)
|
||||
.replace("__INDEX_DATA__", &serde_json::to_string(&data)?)
|
||||
.replace("__INDEX_DATA__", &index_data)
|
||||
};
|
||||
res.headers_mut()
|
||||
.typed_insert(ContentLength(output.as_bytes().len() as u64));
|
||||
|
||||
Reference in New Issue
Block a user