refactor: make logout works on safari (#442)

This commit is contained in:
sigoden
2024-08-27 16:07:17 +08:00
committed by GitHub
parent 964bf61c37
commit 5b338c40da
5 changed files with 44 additions and 19 deletions

View File

@@ -429,7 +429,8 @@ fn is_readonly_method(method: &Method) -> bool {
|| method == Method::OPTIONS
|| method == Method::HEAD
|| method.as_str() == "PROPFIND"
|| method.as_str() == "AUTH"
|| method.as_str() == "CHECKAUTH"
|| method.as_str() == "LOGOUT"
}
fn strip_prefix<'a>(search: &'a [u8], prefix: &[u8]) -> Option<&'a [u8]> {

View File

@@ -200,11 +200,17 @@ impl Server {
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect();
if method.as_str() == "AUTH" {
if user.is_none() {
self.auth_reject(&mut res)?;
if method.as_str() == "CHECKAUTH" {
match user.clone() {
Some(user) => {
*res.body_mut() = body_full(user);
}
None => self.auth_reject(&mut res)?,
}
return Ok(res);
} else if method.as_str() == "LOGOUT" {
self.auth_reject(&mut res)?;
return Ok(res);
}
let head_only = method == Method::HEAD;
@@ -1722,7 +1728,9 @@ fn is_hidden(hidden: &[String], file_name: &str, is_dir_type: bool) -> bool {
fn set_webdav_headers(res: &mut Response) {
res.headers_mut().insert(
"Allow",
HeaderValue::from_static("GET,HEAD,PUT,OPTIONS,DELETE,PATCH,PROPFIND,COPY,MOVE"),
HeaderValue::from_static(
"GET,HEAD,PUT,OPTIONS,DELETE,PATCH,PROPFIND,COPY,MOVE,CHECKAUTH,LOGOUT",
),
);
res.headers_mut()
.insert("DAV", HeaderValue::from_static("1, 2, 3"));