Xuanwo opened a new pull request, #8843:
URL: https://github.com/apache/opendal/pull/8843

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements. You can link an issue to this PR using the GitHub syntax. For 
example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   None.
   
   # Rationale for this change
   
   `MimeGuessLayer` previously had three bugs:
   
   1. `MimeGuessAccessor::write` injected a guessed `content_type` without 
checking `Capability::write_with_content_type`, causing `write` calls to fail 
with `ErrorKind::Unsupported` when `CapabilityCheckLayer` or strict validation 
sits underneath on services without `write_with_content_type` (such as `fs`, 
`sqlite`, `rocksdb`, `sftp`, and `ftp`).
   2. `MimeGuessAccessor::compose` injected a guessed `content_type` without 
checking `Capability::compose_with_content_type`, causing `compose` calls on 
paths with recognized extensions to fail in `CorrectnessCheckLayer` (enabled by 
default in `Operator::new`) whenever `compose_with_content_type` is `false`.
   3. `rpstat_with_mime` ran `mime_guess::from_path(path)` without checking 
`metadata.is_file()` or trailing slashes. Because 
`Path::new("site.html/").extension()` strips the trailing `/`, 
`stat("site.html/")` tagged directory metadata with file MIME types such as 
`text/html`.
   
   # What changes are included in this PR?
   
   - Check `self.0.capability().write_with_content_type` before injecting a 
guessed `content_type` in `MimeGuessAccessor::write`, preserving any 
caller-supplied `content_type` unchanged.
   - Check `self.0.capability().compose_with_content_type` before injecting a 
guessed `content_type` in `MimeGuessAccessor::compose`, preserving any 
caller-supplied `content_type` unchanged.
   - Skip MIME guessing in `rpstat_with_mime` when `!metadata.is_file()`, and 
return `None` from `mime_from_path` for paths ending with `/`.
   - Document the capability and file-only `stat` behavior on `MimeGuessLayer`.
   - Add unit tests covering directory `stat`/`list` behavior and 
`write`/`compose` capability handling.
   
   # Are there any user-facing changes?
   
   Yes. `MimeGuessLayer` no longer injects guessed `content_type` on `write` or 
`compose` when the underlying service does not support 
`write_with_content_type` / `compose_with_content_type`, and `stat` on 
directory entries no longer receives a guessed file MIME type.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi coding agent
   - Model: Gemini 4 Neon
   - Effort: High
   - Role: Implemented the capability checks and directory `stat` guard in 
`opendal-layer-mime-guess`, updated layer documentation, and added unit tests.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to