Skip to content

fix: include Content-Type in rc stat metadata#49

Closed
overtrue wants to merge 1 commit intomainfrom
fix/issue-46-content-type-20260310
Closed

fix: include Content-Type in rc stat metadata#49
overtrue wants to merge 1 commit intomainfrom
fix/issue-46-content-type-20260310

Conversation

@overtrue
Copy link
Contributor

@overtrue overtrue commented Mar 9, 2026

Summary

  • fix rc stat metadata composition so Content-Type is included under the Metadata section
  • keep custom metadata output and normalize display keys (X-Amz-Meta-*)
  • align JSON metadata payload with the same normalized metadata set

Reproduction

Issue: #46

Using Docker (rustfs/rc:latest + MinIO), rc stat output showed Type: text/plain but did not include Content-Type in metadata.

Changes

  • add normalize_metadata() in crates/cli/src/commands/stat.rs
  • include Content-Type when building metadata for both human and JSON output
  • print a Metadata group in human output and include normalized metadata entries
  • add unit tests for content type and custom metadata normalization

Verification

  • cargo fmt --all
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace
  • Docker-based repro + verification against MinIO with:
    • rustfs/rc:latest (reproduced missing metadata content-type)
    • local patched binary (verified Metadata includes Content-Type)

Risk

  • low: change is scoped to stat output formatting/serialization
  • potential output-shape impact: JSON metadata now includes normalized header-style keys

Related

Copilot AI review requested due to automatic review settings March 9, 2026 17:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes rc stat metadata composition so Content-Type is included in the Metadata section (matching expectations from issue #46), while also normalizing displayed/serialized custom metadata keys to X-Amz-Meta-*.

Changes:

  • Added normalize_metadata() to combine Content-Type plus custom metadata into a normalized, sorted BTreeMap.
  • Updated both human and JSON stat output to use the normalized metadata set (and to print a Metadata group in human output).
  • Added unit tests covering Content-Type inclusion and custom metadata key normalization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +71 to +75
let mut sorted: BTreeMap<_, _> = meta.iter().collect();
for (key, value) in &mut sorted {
out.insert(
format!("X-Amz-Meta-{}", capitalize_meta_key(key)),
(*value).clone(),
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalize_metadata builds an intermediate sorted BTreeMap (meta.iter().collect()) and iterates it mutably, but the final out is already a BTreeMap (deterministic sorting). Consider iterating meta directly and inserting into out (with an explicit owned conversion like to_owned() for values) and avoid &mut iteration to keep this helper simpler.

Suggested change
let mut sorted: BTreeMap<_, _> = meta.iter().collect();
for (key, value) in &mut sorted {
out.insert(
format!("X-Amz-Meta-{}", capitalize_meta_key(key)),
(*value).clone(),
for (key, value) in meta {
out.insert(
format!("X-Amz-Meta-{}", capitalize_meta_key(key)),
value.to_owned(),

Copilot uses AI. Check for mistakes.
Comment on lines +176 to +178
if let Some(metadata) =
normalize_metadata(info.content_type.as_deref(), info.metadata.as_ref())
{
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalize_metadata(...) is recomputed in the human-output branch even though the JSON branch already computes it. Consider computing the normalized metadata once per object and reusing it for both output modes to avoid duplication and potential drift.

Copilot uses AI. Check for mistakes.
@overtrue
Copy link
Contributor Author

overtrue commented Mar 9, 2026

Closing as duplicate of #48, which already addresses issue #46.

@overtrue overtrue closed this Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The metadata returned by rc stat does not include Content Type in the same way mc stat does

2 participants