Version Description
- Disable the compatibility with LiteSpeed servers as purging its cache with variation cookies isn't working per spec
Download this release
Release Info
Developer | nitropack |
Plugin | NitroPack |
Version | 1.5.6 |
Comparing to | |
See all releases |
Code changes from version 1.5.5 to 1.5.6
- classes/Integration/Hosting/WPX.php +13 -0
- classes/Integration/Server/LiteSpeed.php +13 -8
- constants.php +1 -1
- functions.php +2 -0
- main.php +1 -1
- readme.txt +4 -1
classes/Integration/Hosting/WPX.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace NitroPack\Integration\Hosting;
|
4 |
+
|
5 |
+
class WPX extends Hosting {
|
6 |
+
const STAGE = NULL;
|
7 |
+
|
8 |
+
public static function detect() {
|
9 |
+
$hostname = gethostname();
|
10 |
+
return $hostname && (preg_match("/wpx\.net$/", $hostname) || preg_match("/wpxhosting\.com$/", $hostname));
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
classes/Integration/Server/LiteSpeed.php
CHANGED
@@ -4,17 +4,19 @@ namespace NitroPack\Integration\Server;
|
|
4 |
|
5 |
class LiteSpeed {
|
6 |
const STAGE = "very_early";
|
|
|
7 |
|
8 |
public static function detect() {
|
9 |
return !empty($_SERVER["X-LSCACHE"]) || ( !empty($_SERVER["SERVER_SOFTWARE"]) && strtolower($_SERVER["SERVER_SOFTWARE"]) == "litespeed" );
|
10 |
}
|
11 |
|
12 |
public static function isCacheEnabled() {
|
|
|
13 |
return self::detect() && !empty($_SERVER["X-LSCACHE"]) && in_array("on", array_map("trim", explode(",", $_SERVER["X-LSCACHE"])));
|
14 |
}
|
15 |
|
16 |
public static function isCachePossible() {
|
17 |
-
return isset($_COOKIE[
|
18 |
}
|
19 |
|
20 |
public static function sendCacheHeader($maxAge = NULL) {
|
@@ -49,13 +51,11 @@ class LiteSpeed {
|
|
49 |
}
|
50 |
|
51 |
public function init($stage) {
|
52 |
-
|
53 |
-
header("Accept-CH: Sec-CH-UA-Mobile");
|
54 |
-
}
|
55 |
-
|
56 |
if (self::isCacheEnabled()) {
|
57 |
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
58 |
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
|
|
59 |
add_action('nitropack_cacheable_cache_headers', [$this, 'allowProxyCache']);
|
60 |
}
|
61 |
}
|
@@ -68,16 +68,21 @@ class LiteSpeed {
|
|
68 |
self::purge();
|
69 |
}
|
70 |
|
|
|
|
|
|
|
|
|
71 |
public function allowProxyCache() {
|
72 |
-
header("X-LiteSpeed-Vary: cookie=_lscache_vary_device");
|
73 |
if (self::isCachePossible()) {
|
74 |
self::sendCacheHeader(3600);
|
75 |
} else if (!empty($_SERVER["HTTP_USER_AGENT"])) {
|
76 |
$device = new \NitroPack\SDK\Device($_SERVER["HTTP_USER_AGENT"]);
|
77 |
if ($device->isMobile()) {
|
78 |
-
nitropack_setcookie(
|
|
|
|
|
79 |
} else {
|
80 |
-
nitropack_setcookie(
|
81 |
}
|
82 |
}
|
83 |
}
|
4 |
|
5 |
class LiteSpeed {
|
6 |
const STAGE = "very_early";
|
7 |
+
const DEVICE_COOKIE = "ls_nitro_device";
|
8 |
|
9 |
public static function detect() {
|
10 |
return !empty($_SERVER["X-LSCACHE"]) || ( !empty($_SERVER["SERVER_SOFTWARE"]) && strtolower($_SERVER["SERVER_SOFTWARE"]) == "litespeed" );
|
11 |
}
|
12 |
|
13 |
public static function isCacheEnabled() {
|
14 |
+
return false;
|
15 |
return self::detect() && !empty($_SERVER["X-LSCACHE"]) && in_array("on", array_map("trim", explode(",", $_SERVER["X-LSCACHE"])));
|
16 |
}
|
17 |
|
18 |
public static function isCachePossible() {
|
19 |
+
return isset($_COOKIE[self::DEVICE_COOKIE]);
|
20 |
}
|
21 |
|
22 |
public static function sendCacheHeader($maxAge = NULL) {
|
51 |
}
|
52 |
|
53 |
public function init($stage) {
|
54 |
+
return;
|
|
|
|
|
|
|
55 |
if (self::isCacheEnabled()) {
|
56 |
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
57 |
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
58 |
+
add_action('nitropack_early_cache_headers', [$this, 'setupVary']);
|
59 |
add_action('nitropack_cacheable_cache_headers', [$this, 'allowProxyCache']);
|
60 |
}
|
61 |
}
|
68 |
self::purge();
|
69 |
}
|
70 |
|
71 |
+
public function setupVary() {
|
72 |
+
header("X-LiteSpeed-Vary: cookie=" . self::DEVICE_COOKIE);
|
73 |
+
}
|
74 |
+
|
75 |
public function allowProxyCache() {
|
|
|
76 |
if (self::isCachePossible()) {
|
77 |
self::sendCacheHeader(3600);
|
78 |
} else if (!empty($_SERVER["HTTP_USER_AGENT"])) {
|
79 |
$device = new \NitroPack\SDK\Device($_SERVER["HTTP_USER_AGENT"]);
|
80 |
if ($device->isMobile()) {
|
81 |
+
nitropack_setcookie(self::DEVICE_COOKIE, "mobile", time() + 86400);
|
82 |
+
} else if ($device->isTablet()) {
|
83 |
+
nitropack_setcookie(self::DEVICE_COOKIE, "tablet", time() + 86400);
|
84 |
} else {
|
85 |
+
nitropack_setcookie(self::DEVICE_COOKIE, "desktop", time() + 86400);
|
86 |
}
|
87 |
}
|
88 |
}
|
constants.php
CHANGED
@@ -6,7 +6,7 @@ function nitropack_trailingslashit($string) {
|
|
6 |
return rtrim( $string, '/\\' ) . '/';
|
7 |
}
|
8 |
|
9 |
-
define( 'NITROPACK_VERSION', '1.5.
|
10 |
define( 'NITROPACK_OPTION_GROUP', 'nitropack' );
|
11 |
define( 'NITROPACK_DATA_DIR', nitropack_trailingslashit(WP_CONTENT_DIR) . 'nitropack' );
|
12 |
define( 'NITROPACK_CONFIG_FILE', nitropack_trailingslashit(NITROPACK_DATA_DIR) . 'config.json' );
|
6 |
return rtrim( $string, '/\\' ) . '/';
|
7 |
}
|
8 |
|
9 |
+
define( 'NITROPACK_VERSION', '1.5.6' );
|
10 |
define( 'NITROPACK_OPTION_GROUP', 'nitropack' );
|
11 |
define( 'NITROPACK_DATA_DIR', nitropack_trailingslashit(WP_CONTENT_DIR) . 'nitropack' );
|
12 |
define( 'NITROPACK_CONFIG_FILE', nitropack_trailingslashit(NITROPACK_DATA_DIR) . 'config.json' );
|
functions.php
CHANGED
@@ -2488,6 +2488,8 @@ function nitropack_detect_hosting() {
|
|
2488 |
return "closte";
|
2489 |
} else if (\NitroPack\Integration\Hosting\Pagely::detect()) {
|
2490 |
return "pagely";
|
|
|
|
|
2491 |
} else {
|
2492 |
return "unknown";
|
2493 |
}
|
2488 |
return "closte";
|
2489 |
} else if (\NitroPack\Integration\Hosting\Pagely::detect()) {
|
2490 |
return "pagely";
|
2491 |
+
} else if (\NitroPack\Integration\Hosting\WPX::detect()) {
|
2492 |
+
return "wpx";
|
2493 |
} else {
|
2494 |
return "unknown";
|
2495 |
}
|
main.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: NitroPack
|
4 |
Plugin URI: https://nitropack.io/platform/wordpress
|
5 |
Description: Everything you need for a fast website. Simple set up, easy to use, awesome support. Caching, Lazy Loading, Minification, Defer CSS/JS, CDN and more!
|
6 |
-
Version: 1.5.
|
7 |
Author: NitroPack LLC
|
8 |
Author URI: https://nitropack.io/
|
9 |
License: GPL2
|
3 |
Plugin Name: NitroPack
|
4 |
Plugin URI: https://nitropack.io/platform/wordpress
|
5 |
Description: Everything you need for a fast website. Simple set up, easy to use, awesome support. Caching, Lazy Loading, Minification, Defer CSS/JS, CDN and more!
|
6 |
+
Version: 1.5.6
|
7 |
Author: NitroPack LLC
|
8 |
Author URI: https://nitropack.io/
|
9 |
License: GPL2
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: cache,perfomance,optimize,pagespeed,lazy load,cdn,critical css,compression
|
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 5.8
|
6 |
Requires PHP: 5.3
|
7 |
-
Stable tag: 1.5.
|
8 |
License: GNU General Public License, version 2
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -169,6 +169,9 @@ No. We’ve designed NitroPack to be a very lightweight solution that adds no CP
|
|
169 |
|
170 |
== Changelog ==
|
171 |
|
|
|
|
|
|
|
172 |
= 1.5.5 =
|
173 |
* New Feature: Compatibility with Fastly
|
174 |
* New Feature: Compatibility with Closte
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 5.8
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 1.5.6
|
8 |
License: GNU General Public License, version 2
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
169 |
|
170 |
== Changelog ==
|
171 |
|
172 |
+
= 1.5.6 =
|
173 |
+
* Disable the compatibility with LiteSpeed servers as purging its cache with variation cookies isn't working per spec
|
174 |
+
|
175 |
= 1.5.5 =
|
176 |
* New Feature: Compatibility with Fastly
|
177 |
* New Feature: Compatibility with Closte
|