Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate compression #155

Merged
merged 4 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 29 additions & 82 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,21 @@ class Response
'text/x-component' => true,
'text/x-java-source' => true,
'text/x-markdown' => true,

// JavaScript
'application/javascript' => true,
'application/x-javascript' => true,
'text/javascript' => true,
'text/js' => true,

// Icons
'image/x-icon' => true,
'image/vnd.microsoft.icon' => true,

// Scripts
'application/x-perl' => true,
'application/x-httpd-cgi' => true,

// XML and JSON
'text/xml' => true,
'application/xml' => true,
Expand All @@ -222,14 +222,14 @@ class Response
'application/ld+json' => true,
'application/graphql+json' => true,
'application/geo+json' => true,

// Multipart
'multipart/bag' => true,
'multipart/mixed' => true,

// XHTML
'application/xhtml+xml' => true,

// Fonts
'font/ttf' => true,
'font/otf' => true,
Expand All @@ -247,7 +247,7 @@ class Response
'application/eot' => true,
'application/font' => true,
'application/font-sfnt' => true,

// WebAssembly
'application/wasm' => true,
'application/javascript-binast' => true,
Expand Down Expand Up @@ -598,8 +598,9 @@ public function send(string $body = ''): void

$this->appendCookies();

// Compress body
// Compress body only if all conditions are met:
if (
empty($this->headers['content-encoding']) &&
!empty($this->acceptEncoding) &&
$this->isCompressible($this->contentType) &&
strlen($body) > $this->compressionMinSize
Expand Down
1 change: 1 addition & 0 deletions tests/Validator/DomainTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Utopia PHP Framework
*
Expand Down
1 change: 1 addition & 0 deletions tests/Validator/HostTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Utopia PHP Framework
*
Expand Down
1 change: 1 addition & 0 deletions tests/Validator/IPTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Utopia PHP Framework
*
Expand Down
1 change: 1 addition & 0 deletions tests/Validator/URLTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Utopia PHP Framework
*
Expand Down