Allow UTF-8 header values for S3 metadata #373
                
     Draft
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Problem
S3 metadata values were limited to ASCII characters, causing failures when clients sent UTF-8 content (e.g., Chinese, Japanese, emoji). The AWS SDK sends UTF-8 metadata as raw bytes in HTTP headers, but the s3s implementation was calling
HeaderValue::to_str()which only accepts ASCII, leading to "invalid headers" errors.Root Causes
The issue occurred in three places:
parse_opt_metadata): Usedto_str()which fails on non-ASCII bytesOrderedHeaders::from_headers): Failed to build canonical headers for AWS SigV4 when metadata contained UTF-8add_opt_metadata): Didn't properly encode UTF-8 for HTTP header transmissionSolution
Metadata Parsing
Modified
parse_opt_metadata()to:to_str()failsSignature Verification
Updated
OrderedHeaders::from_headers()to:x-amz-meta-*headersBox::leak()to extend lifetime for signature calculation (acceptable for short-lived request objects)Metadata Serialization
Enhanced
add_opt_metadata()to:Testing
Added
test_put_object_with_utf8_metadatain s3s-e2e testing:Compatibility
Fixes #[issue_number]
Original prompt
Fixes #372
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.