This is an automated email from the ASF dual-hosted git repository. koushiro pushed a commit to branch extract-mime-guess-layer in repository https://gitbox.apache.org/repos/asf/opendal.git
commit d28f7d882c537e56338564c73be6b0d85716e715 Author: koushiro <[email protected]> AuthorDate: Thu Dec 11 13:37:28 2025 +0800 refactor: Split mime-guess layer to new crate --- core/Cargo.lock | 12 ++++++- core/Cargo.toml | 3 +- core/core/Cargo.toml | 4 --- core/core/src/layers/mod.rs | 5 --- core/layers/mime-guess/Cargo.toml | 40 ++++++++++++++++++++++ .../mime_guess.rs => layers/mime-guess/src/lib.rs} | 18 +++++----- core/src/lib.rs | 2 ++ 7 files changed, 64 insertions(+), 20 deletions(-) diff --git a/core/Cargo.lock b/core/Cargo.lock index b8671c60a..49913d7d9 100644 --- a/core/Cargo.lock +++ b/core/Cargo.lock @@ -5486,6 +5486,7 @@ dependencies = [ "opendal-layer-capability-check", "opendal-layer-fastmetrics", "opendal-layer-metrics", + "opendal-layer-mime-guess", "opendal-layer-observe-metrics-common", "opendal-layer-otelmetrics", "opendal-layer-prometheus", @@ -5575,7 +5576,6 @@ dependencies = [ "log", "md-5", "mea", - "mime_guess", "mini-moka", "moka", "mongodb", @@ -5704,6 +5704,16 @@ dependencies = [ "opendal-layer-observe-metrics-common", ] +[[package]] +name = "opendal-layer-mime-guess" +version = "0.55.0" +dependencies = [ + "futures", + "mime_guess", + "opendal-core", + "tokio", +] + [[package]] name = "opendal-layer-observe-metrics-common" version = "0.55.0" diff --git a/core/Cargo.toml b/core/Cargo.toml index cae8ccce8..79c29b7ff 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -94,7 +94,7 @@ layers-dtrace = ["opendal-core/layers-dtrace"] layers-fastmetrics = ["dep:opendal-layer-fastmetrics"] layers-fastrace = ["opendal-core/layers-fastrace"] layers-metrics = ["dep:opendal-layer-metrics"] -layers-mime-guess = ["opendal-core/layers-mime-guess"] +layers-mime-guess = ["dep:opendal-layer-mime-guess"] layers-otel-metrics = ["dep:opendal-layer-otelmetrics"] layers-otel-trace = ["opendal-core/layers-otel-trace"] layers-prometheus = ["dep:opendal-layer-prometheus"] @@ -192,6 +192,7 @@ opendal-layer-await-tree = { path = "layers/await-tree", version = "0.55.0", opt opendal-layer-capability-check = { path = "layers/capability-check", version = "0.55.0", optional = true, default-features = false } opendal-layer-observe-metrics-common = { path = "layers/observe-metrics-common", version = "0.55.0", optional = true, default-features = false } opendal-layer-metrics = { path = "layers/metrics", version = "0.55.0", optional = true, default-features = false } +opendal-layer-mime-guess = { path = "layers/mime-guess", version = "0.55.0", optional = true, default-features = false } opendal-layer-otelmetrics = { path = "layers/otelmetrics", version = "0.55.0", optional = true, default-features = false } opendal-layer-prometheus = { path = "layers/prometheus", version = "0.55.0", optional = true, default-features = false } opendal-layer-prometheus-client = { path = "layers/prometheus-client", version = "0.55.0", optional = true, default-features = false } diff --git a/core/core/Cargo.toml b/core/core/Cargo.toml index 24dd72439..76174f733 100644 --- a/core/core/Cargo.toml +++ b/core/core/Cargo.toml @@ -72,8 +72,6 @@ executors-tokio = ["tokio/rt"] # Enable layers chaos support layers-chaos = ["dep:rand"] -# Enable layers mime_guess support -layers-mime-guess = ["dep:mime_guess"] # Enable layers fastrace support. layers-fastrace = ["dep:fastrace"] # Enable layers tracing support. @@ -313,8 +311,6 @@ web-sys = { version = "0.3.77", optional = true, features = [ # Layers # for layers-throttle governor = { version = "0.10.1", optional = true, features = ["std"] } -# for layers-mime-guess -mime_guess = { version = "2.0.5", optional = true } # for layers-fastrace fastrace = { version = "0.7.14", optional = true } # for layers-opentelemetry diff --git a/core/core/src/layers/mod.rs b/core/core/src/layers/mod.rs index 4b1012ff6..582e35b1a 100644 --- a/core/core/src/layers/mod.rs +++ b/core/core/src/layers/mod.rs @@ -47,11 +47,6 @@ mod chaos; #[cfg(feature = "layers-chaos")] pub use chaos::ChaosLayer; -#[cfg(feature = "layers-mime-guess")] -mod mime_guess; -#[cfg(feature = "layers-mime-guess")] -pub use self::mime_guess::MimeGuessLayer; - mod retry; pub use self::retry::RetryInterceptor; pub use self::retry::RetryLayer; diff --git a/core/layers/mime-guess/Cargo.toml b/core/layers/mime-guess/Cargo.toml new file mode 100644 index 000000000..595dea524 --- /dev/null +++ b/core/layers/mime-guess/Cargo.toml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +[package] +description = "Apache OpenDAL MIME guess layer" +name = "opendal-layer-mime-guess" + +authors = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +[package.metadata.docs.rs] +all-features = true + +[dependencies] +mime_guess = "2.0.5" +opendal-core = { path = "../../core", version = "0.55.0", default-features = false } + +[dev-dependencies] +futures = { workspace = true } +opendal-core = { path = "../../core", version = "0.55.0" } +tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } diff --git a/core/core/src/layers/mime_guess.rs b/core/layers/mime-guess/src/lib.rs similarity index 94% rename from core/core/src/layers/mime_guess.rs rename to core/layers/mime-guess/src/lib.rs index 98683d303..6448a5e81 100644 --- a/core/core/src/layers/mime_guess.rs +++ b/core/layers/mime-guess/src/lib.rs @@ -15,8 +15,8 @@ // specific language governing permissions and limitations // under the License. -use crate::Result; -use crate::raw::*; +use opendal_core::Result; +use opendal_core::raw::*; /// A layer that can automatically set `Content-Type` based on the file extension in the path. /// @@ -32,7 +32,7 @@ use crate::raw::*; /// provide `content_type` information, and `mime_guess` will not be called, but will use /// the `content_type` provided by the backend. /// -/// But if you use the [Fs](../services/struct.Fs.html) backend to call `stat`, the backend will +/// But if you use the [Fs](https://docs.rs/opendal/latest/opendal/services/struct.Fs.html) backend to call `stat`, the backend will /// not provide `content_type` information, and our `mime_guess` will be called to provide you with /// appropriate `content_type` information. /// @@ -45,16 +45,16 @@ use crate::raw::*; /// # Examples /// /// ```no_run -/// # use opendal_core::layers::MimeGuessLayer; /// # use opendal_core::services; /// # use opendal_core::Operator; /// # use opendal_core::Result; -/// +/// # use opendal_layer_mime_guess::MimeGuessLayer; +/// # /// # fn main() -> Result<()> { /// let _ = Operator::new(services::Memory::default())? /// .layer(MimeGuessLayer::default()) /// .finish(); -/// Ok(()) +/// # Ok(()) /// # } /// ``` #[derive(Debug, Clone, Default)] @@ -142,11 +142,11 @@ impl<A: Access> LayeredAccess for MimeGuessAccessor<A> { #[cfg(test)] mod tests { use futures::TryStreamExt; + use opendal_core::Metadata; + use opendal_core::Operator; + use opendal_core::services::Memory; use super::*; - use crate::Metadata; - use crate::Operator; - use crate::services::Memory; const DATA: &str = "<html>test</html>"; const CUSTOM: &str = "text/custom"; diff --git a/core/src/lib.rs b/core/src/lib.rs index 594e9d079..f9c416c86 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -60,6 +60,8 @@ pub mod layers { pub use opendal_layer_fastmetrics::*; #[cfg(feature = "layers-metrics")] pub use opendal_layer_metrics::*; + #[cfg(feature = "layers-mime-guess")] + pub use opendal_layer_mime_guess::*; #[cfg(feature = "layers-otel-metrics")] pub use opendal_layer_otelmetrics::*; #[cfg(feature = "layers-prometheus")]
