Skip to content

Commit

Permalink
Bug fix. Only cache GET requests. See: #279
Browse files Browse the repository at this point in the history
  • Loading branch information
JasWSInc committed Sep 30, 2014
1 parent 1be45e2 commit c45b9f0
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions quick-cache/includes/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,31 @@ public function is_get_request_w_query()
return static::$static[__FUNCTION__];

if(!empty($_GET) || isset($_SERVER['QUERY_STRING'][0]))
if(!(isset($_GET['qcABC']) && count($_GET) === 1)) // Ignore this special case.
if(!(isset($_GET['qcABC']) && count($_GET) === 1)) // Special case.
return (static::$static[__FUNCTION__] = TRUE);

return (static::$static[__FUNCTION__] = FALSE);
}

/**
* Is the current request method `POST`, `PUT` or `DELETE`?
*
* @since 14xxxx Updating `is_uncacheable_request_method()` and restoring this one.
*
* @return boolean `TRUE` if current request method is `POST`, `PUT` or `DELETE`.
*
* @note The return value of this function is cached to reduce overhead on repeat calls.
*/
public function is_post_put_delete_request()
{
if(isset(static::$static[__FUNCTION__]))
return static::$static[__FUNCTION__];

if(!empty($_POST)) // Being thorough.
return (static::$static[__FUNCTION__] = TRUE);

if(!empty($_SERVER['REQUEST_METHOD']))
if(in_array(strtoupper($_SERVER['REQUEST_METHOD']), array('POST', 'PUT', 'DELETE'), TRUE))
return (static::$static[__FUNCTION__] = TRUE);

return (static::$static[__FUNCTION__] = FALSE);
Expand All @@ -503,6 +527,7 @@ public function is_get_request_w_query()
/**
* Is the current request method is uncacheable?
*
* @since 14xxxx Reversing logic; only allow `GET` requests to be cached.
* @since 140725 Adding HEAD/OPTIONS/TRACE/CONNECT to the list of uncacheables.
*
* @return boolean `TRUE` if current request method is uncacheable.
Expand All @@ -514,9 +539,11 @@ public function is_uncacheable_request_method()
if(isset(static::$static[__FUNCTION__]))
return static::$static[__FUNCTION__];

if(!empty($_POST)) // Being thorough.
return (static::$static[__FUNCTION__] = TRUE);

if(!empty($_SERVER['REQUEST_METHOD']))
if(in_array(strtoupper($_SERVER['REQUEST_METHOD']),
array('POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT'), TRUE))
if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), array('GET'), TRUE))
return (static::$static[__FUNCTION__] = TRUE);

return (static::$static[__FUNCTION__] = FALSE);
Expand Down

0 comments on commit c45b9f0

Please sign in to comment.