stuttter / wp-spider-cache

Your friendly neighborhood caching solution for WordPress
GNU General Public License v2.0
134 stars 16 forks source link

Only one header of type can be cached #22

Closed dimadin closed 7 years ago

dimadin commented 7 years ago

When there are two or more headers of the same type on the page, only one is stored in the cache. This is because PHP stores multiple headers of the same type while WP Spider Cache assumes there is only one per type (like what server returns).

For example, by default, post's page has two Link headers

Array
(
    [0] => Vary: Cookie
    [1] => Content-Type: text/html; charset=UTF-8
    [2] => X-Pingback: http://example.com/xmlrpc.php
    [3] => Link: <http://example.com/wp-json/>; rel="https://api.w.org/"
    [4] => Link: <http://example.com/?p=1>; rel=shortlink
)

but only last can be saved

foreach ( headers_list() as $header ) {
    list( $k, $v ) = array_map( 'trim', explode( ':', $header, 2 ) );
    $this->cache['headers'][ $k ] = $v;
}
JJJ commented 7 years ago

Good catch! I'll merge your PR and make sure PHP 7.1 doesn't complain (about assuming the array exists.)