Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Addresses requirements to consolidate Content-Type parsing, improve error messages, and support custom validation.

Changes

New module: http/content_type.rs

  • parse_content_type() - centralized parser with detailed error hints
  • validate_content_type() - enforce specific type/subtype requirements
  • is_multipart_form_data() - typed helper for common check
  • ContentTypeError - structured error type with specific variants

Simplified existing code

  • ops/mod.rs: extract_mime() now delegates to centralized parser (12 → 3 lines)
  • ops/signature.rs: uses is_multipart_form_data() helper
  • http/de.rs: added parse_field_value_content_type() for consistency

Error message improvements

Before:

invalid content type: "invalid"

After:

Invalid Content-Type header: "invalid". 
Content-Type should be in format 'type/subtype' (e.g., 'text/plain', 'application/json')

Errors now include:

  • Detected issues (missing type/subtype, malformed syntax, etc.)
  • Expected format with examples
  • Multiple hints when applicable

Custom validation example

use s3s::http::validate_content_type;

let mime: Mime = content_type.parse()?;
validate_content_type(&mime, "application", "json")?;
// Returns descriptive error if type doesn't match

Related to issue requirements for centralized Content-Type handling.

Original prompt

This section details on the original issue you should resolve

<issue_title>Content-Type handling</issue_title>
<issue_description>+ [ ] Extract all content type handling to one place

  • Return detailed error message about invalid content type
  • Support custom content type (?)
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Extract content type handling and improve error messages Centralize Content-Type handling with detailed error messages Nov 18, 2025
Copilot AI requested a review from Nugine November 18, 2025 03:02
Copilot finished work on behalf of Nugine November 18, 2025 03:02
@Nugine Nugine closed this Nov 23, 2025
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.

Content-Type handling

2 participants