Skip to content

built-in mime type exclusion list - #104

Open
pavetheway91 wants to merge 1 commit into
kjdev:masterfrom
pavetheway91:built-in-mime-exclusions
Open

built-in mime type exclusion list#104
pavetheway91 wants to merge 1 commit into
kjdev:masterfrom
pavetheway91:built-in-mime-exclusions

Conversation

@pavetheway91

@pavetheway91 pavetheway91 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Hey

I thought it would be a good idea to ship with a built-in list of common and/or obvious cases of these mime type exclusions. With this implemented, user only has to add any types, which might be missing from the built-in one.

List of these built-in exclusions is also printed to phpinfo();

One of the associated tests was modified to use the built-in list, while another one was modified to use the ini list.

I placed the list to a separate header, so it can be easily be replaced too, if someone wants to compile this with their own list.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added built-in exclusions for media, fonts, PDFs, archives, and already-compressed formats.
    • Compression can be skipped using built-in or configured MIME-type exclusions, including exact matches and type/* wildcards.
    • PHP information now displays the built-in exclusion list.
    • SVG content remains eligible for compression unless explicitly excluded.
  • Documentation

    • Updated configuration guidance with supported MIME types, matching rules, and INI examples.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The extension adds built-in MIME types that bypass Zstandard compression. It checks built-in and configured exclusion lists, reports the built-in list through phpinfo(), documents the configuration behavior, and updates exclusion tests.

Changes

MIME exclusion support

Layer / File(s) Summary
Define and expose built-in exclusions
php_zstd_mimetype_exclude.h, zstd.c, package.xml, README.md
Adds the ZSTD_MIMETYPE_EXCLUDE list. PHP 8+ includes and reports the list. The package includes the header. The README documents built-in and configured exclusions.
Apply MIME exclusions during startup
zstd.c, tests/ob_exclude_001.phpt, tests/ob_exclude_002.phpt, tests/info.phpt
The MIME matching function accepts an exclusion list. Startup skips compression when either exclusion list matches the response MIME type. Tests validate PDF configuration removal, SVG wildcard behavior, and the built-in list reported by phpinfo().

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant Startup as Output compression startup
  participant Matcher as php_zstd_output_mimetype_excluded
  participant Lists as Built-in and configured exclusion lists
  Startup->>Matcher: Check response MIME type
  Matcher->>Lists: Test both exclusion lists
  Lists-->>Matcher: Return match result
  Matcher-->>Startup: Skip compression when matched
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a built-in MIME type exclusion list.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
zstd.c (1)

1561-1565: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a regression test for the built-in exclusion list.

The supplied tests/ob_exclude_002.phpt sets zstd.output_compression_exclude_types=image/*, so it exercises the configured list. It would still pass if the built-in exclusion call were removed. Add a case with an empty INI exclusion setting and Content-Type: image/png.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@zstd.c` around lines 1561 - 1565, Add a regression case covering the built-in
exclusion list in tests/ob_exclude_002.phpt or its related test suite: configure
zstd.output_compression_exclude_types to an empty value, send a response with
Content-Type: image/png, and assert the expected exclusion behavior so the test
fails if php_zstd_output_mimetype_excluded(ZSTD_MIMETYPE_EXCLUDE) is removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@php_zstd_mimetype_exclude.h`:
- Line 23: Update the built-in RAR MIME exclusions in the MIME type list to use
the registered application/vnd.rar value, removing application/x-vnd.rar;
include application/x-rar-compressed only if legacy server responses must remain
supported.

---

Nitpick comments:
In `@zstd.c`:
- Around line 1561-1565: Add a regression case covering the built-in exclusion
list in tests/ob_exclude_002.phpt or its related test suite: configure
zstd.output_compression_exclude_types to an empty value, send a response with
Content-Type: image/png, and assert the expected exclusion behavior so the test
fails if php_zstd_output_mimetype_excluded(ZSTD_MIMETYPE_EXCLUDE) is removed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 775656ab-802e-4d31-a18f-7457fe4d72dd

📥 Commits

Reviewing files that changed from the base of the PR and between 3ef892e and 38d21a7.

📒 Files selected for processing (4)
  • README.md
  • php_zstd_mimetype_exclude.h
  • tests/ob_exclude_001.phpt
  • zstd.c
💤 Files with no reviewable changes (1)
  • tests/ob_exclude_001.phpt

Comment thread php_zstd_mimetype_exclude.h
@pavetheway91
pavetheway91 force-pushed the built-in-mime-exclusions branch from 38d21a7 to bc9a945 Compare July 31, 2026 22:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/ob_exclude_002.phpt`:
- Line 16: Update the test setup in tests/ob_exclude_002.phpt so
zstd.output_compression_exclude_types no longer matches the image/svg
Content-Type, allowing the test to exercise the built-in exclusion list. Use a
non-matching configured value while preserving configured wildcard coverage in a
separate test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 466cfe81-0fbc-41f8-bc05-e960e0546544

📥 Commits

Reviewing files that changed from the base of the PR and between 38d21a7 and bc9a945.

📒 Files selected for processing (5)
  • README.md
  • php_zstd_mimetype_exclude.h
  • tests/ob_exclude_001.phpt
  • tests/ob_exclude_002.phpt
  • zstd.c
💤 Files with no reviewable changes (1)
  • tests/ob_exclude_001.phpt
🚧 Files skipped from review as they are similar to previous changes (3)
  • README.md
  • zstd.c
  • php_zstd_mimetype_exclude.h

Comment thread tests/ob_exclude_002.phpt Outdated
@pavetheway91
pavetheway91 force-pushed the built-in-mime-exclusions branch from bc9a945 to c95cea4 Compare August 2, 2026 13:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 92-93: Update the README statement about locating the MIME-type
list through phpinfo() to specify that this visibility is available only in PHP
8 and later, and document an alternative inspection method for older supported
PHP versions if one exists.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 505f7422-cf4c-487a-a4ad-524568dd5011

📥 Commits

Reviewing files that changed from the base of the PR and between bc9a945 and c95cea4.

📒 Files selected for processing (5)
  • README.md
  • php_zstd_mimetype_exclude.h
  • tests/ob_exclude_001.phpt
  • tests/ob_exclude_002.phpt
  • zstd.c
💤 Files with no reviewable changes (1)
  • tests/ob_exclude_001.phpt
🚧 Files skipped from review as they are similar to previous changes (3)
  • php_zstd_mimetype_exclude.h
  • tests/ob_exclude_002.phpt
  • zstd.c

Comment thread README.md
Comment thread php_zstd_mimetype_exclude.h Outdated
Comment thread tests/ob_exclude_002.phpt Outdated
@pavetheway91
pavetheway91 force-pushed the built-in-mime-exclusions branch from 9825967 to 1f704d2 Compare August 4, 2026 16:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/info.phpt`:
- Line 79: Update the MIME-list extraction in tests/info.phpt to use the offset
matching the 42-byte $search prefix instead of skipping the first MIME
character; keep the existing explode-based parsing unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1b02083d-148f-4799-9429-296cf27ae517

📥 Commits

Reviewing files that changed from the base of the PR and between 9825967 and 1f704d2.

📒 Files selected for processing (7)
  • README.md
  • package.xml
  • php_zstd_mimetype_exclude.h
  • tests/info.phpt
  • tests/ob_exclude_001.phpt
  • tests/ob_exclude_002.phpt
  • zstd.c
💤 Files with no reviewable changes (1)
  • tests/ob_exclude_001.phpt
🚧 Files skipped from review as they are similar to previous changes (5)
  • package.xml
  • php_zstd_mimetype_exclude.h
  • README.md
  • tests/ob_exclude_002.phpt
  • zstd.c

Comment thread tests/info.phpt Outdated
}
}
if ($mimeIndex) {
$types = explode(', ', substr($lines[$mimeIndex], 43));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Extract the MIME list at the correct offset.

Line 79 skips the first byte of the first MIME type. $search is 42 bytes long, but substr() starts at offset 43. The regex accepts the truncated value, so this test does not validate the first MIME type.

Proposed fix
-            $types = explode(', ', substr($lines[$mimeIndex], 43));
+            $types = explode(', ', substr($lines[$mimeIndex], strlen($search)));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$types = explode(', ', substr($lines[$mimeIndex], 43));
$types = explode(', ', substr($lines[$mimeIndex], strlen($search)));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/info.phpt` at line 79, Update the MIME-list extraction in
tests/info.phpt to use the offset matching the 42-byte $search prefix instead of
skipping the first MIME character; keep the existing explode-based parsing
unchanged.

@pavetheway91
pavetheway91 force-pushed the built-in-mime-exclusions branch from 1f704d2 to 7006cb4 Compare August 4, 2026 16: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