Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ readme = "README.md"
description = "Rust WebDAV server library. A fork of the webdav-handler crate."
repository = "https://github.com/messense/dav-server-rs"
authors = ["Miquel van Smoorenburg <mike@langeraar.net>", "messense <messense@icloud.com>"]
edition = "2018"
edition = "2024"
license = "Apache-2.0"
keywords = ["webdav"]
categories = ["web-programming"]
Expand Down
4 changes: 2 additions & 2 deletions examples/actix.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::io;

use actix_web::{web, App, HttpServer};
use actix_web::{App, HttpServer, web};
use dav_server::actix::*;
use dav_server::{fakels::FakeLs, localfs::LocalFs, DavConfig, DavHandler};
use dav_server::{DavConfig, DavHandler, fakels::FakeLs, localfs::LocalFs};

pub async fn dav_handler(req: DavRequest, davhandler: web::Data<DavHandler>) -> DavResponse {
if let Some(prefix) = req.prefix() {
Expand Down
6 changes: 3 additions & 3 deletions examples/auth.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::{convert::Infallible, fmt::Display, net::SocketAddr, path::Path};

use futures_util::{stream, StreamExt};
use futures_util::{StreamExt, stream};
use http::{Request, Response, StatusCode};
use hyper::{body::Incoming, server::conn::http1, service::service_fn};
use hyper_util::rt::TokioIo;
use tokio::{net::TcpListener, task::spawn};

use dav_server::{
DavHandler,
body::Body,
davpath::DavPath,
fakels::FakeLs,
Expand All @@ -15,7 +16,6 @@ use dav_server::{
OpenOptions, ReadDirMeta,
},
localfs::LocalFs,
DavHandler,
};

/// The server example demonstrates a limited scope policy for access to the file system.
Expand Down Expand Up @@ -129,7 +129,7 @@ enum Filter {

impl Filter {
fn from_request(request: &Request<Incoming>) -> Result<Self, Box<dyn Display>> {
use headers::{authorization::Basic, Authorization, HeaderMapExt};
use headers::{Authorization, HeaderMapExt, authorization::Basic};

let auth = request
.headers()
Expand Down
2 changes: 1 addition & 1 deletion examples/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use hyper::{server::conn::http1, service::service_fn};
use hyper_util::rt::TokioIo;
use tokio::net::TcpListener;

use dav_server::{fakels::FakeLs, localfs::LocalFs, DavHandler};
use dav_server::{DavHandler, fakels::FakeLs, localfs::LocalFs};

#[tokio::main]
async fn main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/sample-litmus-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use std::{convert::Infallible, error::Error, net::SocketAddr};

use clap::Parser;
use headers::{authorization::Basic, Authorization, HeaderMapExt};
use headers::{Authorization, HeaderMapExt, authorization::Basic};
use hyper::{server::conn::http1, service::service_fn};
use hyper_util::rt::TokioIo;
use tokio::net::TcpListener;

use dav_server::{body::Body, fakels, localfs, memfs, memls, DavConfig, DavHandler};
use dav_server::{DavConfig, DavHandler, body::Body, fakels, localfs, memfs, memls};

#[derive(Clone)]
struct Server {
Expand Down
4 changes: 2 additions & 2 deletions src/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use std::{

use actix_web::body::BoxBody;
use actix_web::error::PayloadError;
use actix_web::{dev, Error, FromRequest, HttpRequest, HttpResponse};
use actix_web::{Error, FromRequest, HttpRequest, HttpResponse, dev};
use bytes::Bytes;
use futures_util::{future, Stream};
use futures_util::{Stream, future};
use pin_project::pin_project;

/// http::Request compatibility.
Expand Down
22 changes: 10 additions & 12 deletions src/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ pub(crate) fn http_if_match(req: &Request, meta: Option<&dyn DavMetaData>) -> Op
if let Some(r) = req.headers().typed_get::<davheaders::IfMatch>() {
let etag = meta.and_then(ETag::from_meta);
if !etaglist_match(&r.0, meta.is_some(), etag.as_ref()) {
trace!("precondition fail: If-Match {:?}", r);
trace!("precondition fail: If-Match {r:?}");
return Some(StatusCode::PRECONDITION_FAILED);
}
} else if let Some(r) = req.headers().typed_get::<headers::IfUnmodifiedSince>() {
match file_modified {
None => return Some(StatusCode::PRECONDITION_FAILED),
Some(file_modified) => {
if round_time(file_modified) > round_time(r) {
trace!("precondition fail: If-Unmodified-Since {:?}", r);
trace!("precondition fail: If-Unmodified-Since {r:?}");
return Some(StatusCode::PRECONDITION_FAILED);
}
}
Expand All @@ -76,22 +76,20 @@ pub(crate) fn http_if_match(req: &Request, meta: Option<&dyn DavMetaData>) -> Op
if let Some(r) = req.headers().typed_get::<davheaders::IfNoneMatch>() {
let etag = meta.and_then(ETag::from_meta);
if etaglist_match(&r.0, meta.is_some(), etag.as_ref()) {
trace!("precondition fail: If-None-Match {:?}", r);
trace!("precondition fail: If-None-Match {r:?}");
if req.method() == Method::GET || req.method() == Method::HEAD {
return Some(StatusCode::NOT_MODIFIED);
} else {
return Some(StatusCode::PRECONDITION_FAILED);
}
}
} else if let Some(r) = req.headers().typed_get::<headers::IfModifiedSince>() {
if req.method() == Method::GET || req.method() == Method::HEAD {
if let Some(file_modified) = file_modified {
if round_time(file_modified) <= round_time(r) {
trace!("not-modified If-Modified-Since {:?}", r);
return Some(StatusCode::NOT_MODIFIED);
}
}
}
} else if let Some(r) = req.headers().typed_get::<headers::IfModifiedSince>()
&& (req.method() == Method::GET || req.method() == Method::HEAD)
&& let Some(file_modified) = file_modified
&& round_time(file_modified) <= round_time(r)
{
trace!("not-modified If-Modified-Since {r:?}");
return Some(StatusCode::NOT_MODIFIED);
}
None
}
Expand Down
36 changes: 18 additions & 18 deletions src/davhandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use http_body_util::BodyExt;
use crate::body::{Body, StreamBody};
use crate::davheaders;
use crate::davpath::DavPath;
use crate::util::{dav_method, DavMethod, DavMethodSet};
use crate::util::{DavMethod, DavMethodSet, dav_method};

use crate::DavResult;
use crate::errors::DavError;
use crate::fs::*;
use crate::ls::*;
use crate::voidfs::{is_voidfs, VoidFs};
use crate::DavResult;
use crate::voidfs::{VoidFs, is_voidfs};

/// WebDAV request handler.
///
Expand Down Expand Up @@ -416,7 +416,7 @@ where
resp
}
Err(err) => {
debug!("== END REQUEST result {:?}", err);
debug!("== END REQUEST result {err:?}");
let mut resp = Response::builder();
if is_ms && err.statuscode() == StatusCode::NOT_FOUND {
// This is an attempt to convince Windows to not
Expand Down Expand Up @@ -459,10 +459,10 @@ where
};

// debug when running the webdav litmus tests.
if log_enabled!(log::Level::Debug) {
if let Some(t) = req.headers().typed_get::<davheaders::XLitmus>() {
debug!("X-Litmus: {:?}", t);
}
if log_enabled!(log::Level::Debug)
&& let Some(t) = req.headers().typed_get::<davheaders::XLitmus>()
{
debug!("X-Litmus: {t:?}");
}

// translate HTTP method to Webdav method.
Expand Down Expand Up @@ -497,15 +497,15 @@ where
}

// see if method is allowed.
if let Some(ref a) = self.allow {
if !a.contains(method) {
debug!(
"method {} not allowed on request {}",
req.method(),
req.uri()
);
return Err(DavError::StatusClose(StatusCode::METHOD_NOT_ALLOWED));
}
if let Some(ref a) = self.allow
&& !a.contains(method)
{
debug!(
"method {} not allowed on request {}",
req.method(),
req.uri()
);
return Err(DavError::StatusClose(StatusCode::METHOD_NOT_ALLOWED));
}

// make sure the request path is valid.
Expand All @@ -532,7 +532,7 @@ where
}
}

debug!("== START REQUEST {:?} {}", method, path);
debug!("== START REQUEST {method:?} {path}");

match method {
DavMethod::Options => self.handle_options(&req).await,
Expand Down
26 changes: 13 additions & 13 deletions src/davheaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn map_invalid(_e: impl std::error::Error) -> headers::Error {
}

macro_rules! header {
($tname:ident, $hname:ident, $sname:expr) => {
($tname:ident, $hname:ident, $sname:expr_2021) => {
lazy_static! {
pub static ref $hname: HeaderName = HeaderName::from_static($sname);
}
Expand Down Expand Up @@ -226,7 +226,7 @@ impl Header for Timeout {
}
first = false;
match *s {
DavTimeout::Seconds(n) => value.push_str(&format!("Second-{}", n)),
DavTimeout::Seconds(n) => value.push_str(&format!("Second-{n}")),
DavTimeout::Infinite => value.push_str("Infinite"),
}
}
Expand All @@ -250,10 +250,10 @@ impl Header for Destination {
if s.starts_with('/') {
return Ok(Destination(s.to_string()));
}
if let Some(caps) = RE_URL.captures(s) {
if let Some(path) = caps.get(1) {
return Ok(Destination(path.as_str().to_string()));
}
if let Some(caps) = RE_URL.captures(s)
&& let Some(path) = caps.get(1)
{
return Ok(Destination(path.as_str().to_string()));
}
Err(invalid())
}
Expand Down Expand Up @@ -313,7 +313,7 @@ impl ETag {
} else {
let w = if weak { "W/" } else { "" };
Ok(ETag {
tag: format!("{}\"{}\"", w, t),
tag: format!("{w}\"{t}\""),
weak,
})
}
Expand All @@ -322,7 +322,7 @@ impl ETag {
pub fn from_meta(meta: &dyn DavMetaData) -> Option<ETag> {
let tag = meta.etag()?;
Some(ETag {
tag: format!("\"{}\"", tag),
tag: format!("\"{tag}\""),
weak: false,
})
}
Expand Down Expand Up @@ -587,9 +587,9 @@ impl Header for XUpdateRange {
{
let value = match *self {
XUpdateRange::Append => "append".to_string(),
XUpdateRange::FromTo(b, e) => format!("{}-{}", b, e),
XUpdateRange::AllFrom(b) => format!("{}-", b),
XUpdateRange::Last(e) => format!("-{}", e),
XUpdateRange::FromTo(b, e) => format!("{b}-{e}"),
XUpdateRange::AllFrom(b) => format!("{b}-"),
XUpdateRange::Last(e) => format!("-{e}"),
};
values.extend(std::iter::once(HeaderValue::from_str(&value).unwrap()));
}
Expand Down Expand Up @@ -654,10 +654,10 @@ enum IfState {

// helpers.
fn is_whitespace(c: u8) -> bool {
b" \t\r\n".iter().any(|&x| x == c)
b" \t\r\n".contains(&c)
}
fn is_special(c: u8) -> bool {
b"<>()[]".iter().any(|&x| x == c)
b"<>()[]".contains(&c)
}

fn trim_left(mut out: &'_ [u8]) -> &'_ [u8] {
Expand Down
13 changes: 6 additions & 7 deletions src/davpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Error for ParseError {

impl std::fmt::Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}

Expand Down Expand Up @@ -422,12 +422,11 @@ impl DavPathRef {
pub(crate) fn get_mime_type_str(&self) -> &'static str {
let name = self.file_name_bytes();
let d = name.rsplitn(2, |&c| c == b'.').collect::<Vec<&[u8]>>();
if d.len() > 1 {
if let Ok(ext) = std::str::from_utf8(d[0]) {
if let Some(t) = mime_guess::from_ext(ext).first_raw() {
return t;
}
}
if d.len() > 1
&& let Ok(ext) = std::str::from_utf8(d[0])
&& let Some(t) = mime_guess::from_ext(ext).first_raw()
{
return t;
}
"application/octet-stream"
}
Expand Down
18 changes: 9 additions & 9 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl std::fmt::Display for DavError {
DavError::XmlReaderError(_) => write!(f, "XML parse error"),
DavError::XmlWriterError(_) => write!(f, "XML generate error"),
DavError::IoError(_) => write!(f, "I/O error"),
_ => write!(f, "{:?}", self),
_ => write!(f, "{self:?}"),
}
}
}
Expand All @@ -63,7 +63,7 @@ impl From<DavError> for io::Error {
match e {
DavError::IoError(e) => e,
DavError::FsError(e) => e.into(),
_ => io::Error::new(io::ErrorKind::Other, e),
_ => io::Error::other(e),
}
}
}
Expand Down Expand Up @@ -118,16 +118,16 @@ impl From<futures_channel::mpsc::SendError> for DavError {

fn fserror_to_ioerror(e: FsError) -> io::Error {
match e {
FsError::NotImplemented => io::Error::new(io::ErrorKind::Other, "NotImplemented"),
FsError::GeneralFailure => io::Error::new(io::ErrorKind::Other, "GeneralFailure"),
FsError::NotImplemented => io::Error::other("NotImplemented"),
FsError::GeneralFailure => io::Error::other("GeneralFailure"),
FsError::Exists => io::Error::new(io::ErrorKind::AlreadyExists, "Exists"),
FsError::NotFound => io::Error::new(io::ErrorKind::NotFound, "Notfound"),
FsError::Forbidden => io::Error::new(io::ErrorKind::PermissionDenied, "Forbidden"),
FsError::InsufficientStorage => io::Error::new(io::ErrorKind::Other, "InsufficientStorage"),
FsError::LoopDetected => io::Error::new(io::ErrorKind::Other, "LoopDetected"),
FsError::PathTooLong => io::Error::new(io::ErrorKind::Other, "PathTooLong"),
FsError::TooLarge => io::Error::new(io::ErrorKind::Other, "TooLarge"),
FsError::IsRemote => io::Error::new(io::ErrorKind::Other, "IsRemote"),
FsError::InsufficientStorage => io::Error::other("InsufficientStorage"),
FsError::LoopDetected => io::Error::other("LoopDetected"),
FsError::PathTooLong => io::Error::other("PathTooLong"),
FsError::TooLarge => io::Error::other("TooLarge"),
FsError::IsRemote => io::Error::other("IsRemote"),
}
}

Expand Down
Loading
Loading