Skip to content

Commit

Permalink
Merge pull request #155 from utopia-php/fix-prevent-duplicate-compres…
Browse files Browse the repository at this point in the history
…sion

fix: duplicate compression
  • Loading branch information
Meldiron authored Feb 24, 2025
2 parents e91d4c5 + a1efe3e commit 81f4a3f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 91 deletions.
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

0 comments on commit 81f4a3f

Please sign in to comment.