Skip to content

Updates for content type detection - #101

Merged
djthorpe merged 3 commits into
mainfrom
djt/1013/text-content-type
Oct 13, 2026
Merged

djthorpe merged 3 commits into
mainfrom
djt/1013/text-content-type

Conversation

@djthorpe

@djthorpe djthorpe commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Updates for content type detection, especially for text/* and application/zip types.

ContentType sniffs the content first. When the sniffed type is generic, the file extension's type is used instead, if it's more specific:

  • Plain text (text/plain) is refined by:

    • a text type, such as text/markdown for .md;
    • an application type that is text, such as application/json, or a registered type such as application/vnd.google-apps.document.

    It's never refined by a binary type: an image, audio, video or font type, application/octet-stream, or a ZIP archive.

  • A ZIP archive (application/zip) is refined by a document type that is a ZIP archive, such as Office Open XML, OpenDocument, or a type ending in +zip. OpenDocument's flat XML types (-flat-xml) are excluded, because those files are XML.

  • Parameters: the sniffed parameters, such as the charset, are kept.

The extension types come from mime.AddExtensionType or the system's types, so the caller registers the document types it handles. The package's own table keeps only its media extensions.

🤖 Generated with Claude Code

@djthorpe djthorpe self-assigned this Oct 13, 2026
Copilot AI balanced review requested due to automatic review settings October 13, 2026 12:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The ZIP refinement incorrectly accepts non-archive OpenDocument flat-XML MIME types.

1 open finding
What changed in this PR

Improves MIME detection by refining sniffed text and ZIP types using file extensions.

Changes:

  • Adds Markdown and ZIP-based document MIME mappings.
  • Preserves sniffed charset parameters during refinement.
  • Adds coverage for text, binary, and ZIP detection.
File Description
metadata/​mime.go Adds extension-aware MIME refinement.
metadata/​mime_test.go Tests Markdown and archive refinement behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread metadata/mime.go Outdated
djthorpe and others added 2 commits October 13, 2026 14:24
- A zip archive isn't refined to an OpenDocument flat XML type, such as
  .fodt, as it's XML rather than a zip archive

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The document extensions are removed from the package's table, so the
  types of extensions are those registered by the caller, with
  mime.AddExtensionType, or the system's
- Plain text is refined by an application type which is text, such as
  application/json, or a registered type, but not by a binary type, such as
  an image, application/octet-stream, or a zip archive

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@djthorpe
djthorpe merged commit c42fbaf into main Oct 13, 2026
9 checks passed
@djthorpe
djthorpe deleted the djt/1013/text-content-type branch October 13, 2026 13:36
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.

2 participants