Skip to content

Commit 2074ddb

Browse files
fix(http): bumped version of tinify-php to 1.6.4
1 parent d2f12eb commit 2074ddb

5 files changed

Lines changed: 28 additions & 12 deletions

File tree

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vendor/tinify/Tinify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Tinify;
44

5-
const VERSION = "1.6.2";
5+
const VERSION = "1.6.4";
66

77
class Tinify {
88
const AUTHENTICATED = true;

src/vendor/tinify/Tinify/Client.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private static function caBundle() {
1919
return __DIR__ . "/../data/cacert.pem";
2020
}
2121

22-
function __construct($key, $appIdentifier = NULL, $proxy = NULL) {
22+
function __construct($key, $app_identifier = NULL, $proxy = NULL) {
2323
$curl = curl_version();
2424

2525
if (!($curl["features"] & CURL_VERSION_SSL)) {
@@ -31,15 +31,19 @@ function __construct($key, $appIdentifier = NULL, $proxy = NULL) {
3131
throw new ClientException("Your curl version {$version} is outdated; please upgrade to 7.18.1 or higher");
3232
}
3333

34-
$userAgent = join(" ", array_filter(array(self::userAgent(), $appIdentifier)));
35-
34+
# Set minimum TLS version to 1.2, CURL_SSLVERSION_TLSv1_2 is not available in curl < 7.34.0
35+
# Additionally old PHP versions may not support this constant
36+
$tlsVersion = ($curl["version_number"] < 0x072200)
37+
? 6
38+
: (defined('CURL_SSLVERSION_TLSv1_2') ? CURL_SSLVERSION_TLSv1_2 : 6);
3639
$this->options = array(
3740
CURLOPT_RETURNTRANSFER => true,
3841
CURLOPT_HEADER => true,
3942
CURLOPT_USERPWD => $key ? ("api:" . $key) : NULL,
4043
CURLOPT_CAINFO => self::caBundle(),
4144
CURLOPT_SSL_VERIFYPEER => true,
42-
CURLOPT_USERAGENT => $userAgent,
45+
CURLOPT_USERAGENT => join(" ", array_filter(array(self::userAgent(), $app_identifier))),
46+
CURLOPT_SSLVERSION => $tlsVersion,
4347
);
4448

4549
if ($proxy) {
@@ -108,7 +112,11 @@ function request($method, $url, $body = NULL) {
108112
if (is_string($response)) {
109113
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
110114
$headerSize = curl_getinfo($request, CURLINFO_HEADER_SIZE);
111-
curl_close($request);
115+
if (PHP_VERSION_ID < 80000) {
116+
curl_close($request);
117+
} else {
118+
unset($request);
119+
}
112120

113121
$headers = self::parseHeaders(substr($response, 0, $headerSize));
114122
$responseBody = substr($response, $headerSize);
@@ -177,7 +185,11 @@ function request($method, $url, $body = NULL) {
177185
return (object) array("body" => $responseBody, "headers" => $headers);
178186
} else {
179187
$message = sprintf("%s (#%d)", curl_error($request), curl_errno($request));
180-
curl_close($request);
188+
if (PHP_VERSION_ID < 80000) {
189+
curl_close($request);
190+
} else {
191+
unset($request);
192+
}
181193
if ($retries > 0) continue;
182194
throw new ConnectionException("Error while connecting: " . $message);
183195
}

src/vendor/tinify/Tinify/Source.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ public function transform($options) {
5353
}
5454

5555
public function result() {
56-
$response = Tinify::getClient()->request("get", $this->url, $this->commands);
56+
$has_commands = !empty($this->commands);
57+
$method = $has_commands ? "post" : "get";
58+
$body = $has_commands ? $this->commands : null;
59+
$response = Tinify::getClient()->request($method, $this->url, $body);
5760
return new Result($response->headers, $response->body);
5861
}
5962

test/unit/TinyCompressSharedTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ public function test_should_compress_and_convert_when_convert_is_true()
361361
'headers' => array(
362362
'location' => 'https://api.tinify.com/output/compressed.avif',
363363
'content-type' => 'image/avif',
364+
'content-length' => strlen($compressed_avif),
364365
'compression-count' => 12,
365366
),
366367
'body' => $compressed_avif,

0 commit comments

Comments
 (0)