Browse files

Prevents flash sweep for HEAD requests like suggested by @msaspence i…

…n issue #20.

Can be useful when using browser extensions like webug in Chrome which
send a HEAD request after each GET or POST request.
  • Loading branch information...
1 parent bf5fb97 commit 491bbaf87667d0d754d0e4446edd4272b4e4a349 Fabrice Luraine committed with CBeerta May 30, 2011
Showing with 24 additions and 11 deletions.
  1. +14 −10 lib/limonade.php
  2. +10 −1 tests/functional.php
View
24 lib/limonade.php
@@ -449,21 +449,25 @@ function autoload_controller($callback)
function stop_and_exit($exit = true)
{
call_if_exists('before_exit', $exit);
- $flash_sweep = true;
$headers = headers_list();
- foreach($headers as $header)
- {
- // If a Content-Type header exists, flash_sweep only if is text/html
- // Else if there's no Content-Type header, flash_sweep by default
- if(stripos($header, 'Content-Type:') === 0)
+ if(request_is_head())
+ {
+ ob_end_clean();
+ } else {
+ $flash_sweep = true;
+ foreach($headers as $header)
{
- $flash_sweep = stripos($header, 'Content-Type: text/html') === 0;
- break;
+ // If a Content-Type header exists, flash_sweep only if is text/html
+ // Else if there's no Content-Type header, flash_sweep by default
+ if(stripos($header, 'Content-Type:') === 0)
+ {
+ $flash_sweep = stripos($header, 'Content-Type: text/html') === 0;
+ break;
+ }
}
+ if($flash_sweep) flash_sweep();
}
- if($flash_sweep) flash_sweep();
if(defined('SID')) session_write_close();
- if(request_is_head()) ob_end_clean();
if($exit) exit;
}
View
11 tests/functional.php
@@ -184,6 +184,15 @@ function test_functional_flash()
$response = curl_exec($ch);
assert_match("/ON DISPLAY 2/", $response);
+ # Run a HEAD request on a page where there is no new flash
+ # message set. Previous flash message should still be
+ # there after this request.
+ curl_setopt($ch, CURLOPT_URL, $path.'four');
+ curl_setopt($ch, CURLOPT_NOBODY, TRUE);
+ curl_setopt($ch, CURLOPT_HEADER, 1);
+ $response = curl_exec($ch);
+
+ curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_URL, $path.'three');
$response = curl_exec($ch);
assert_match("/ON DISPLAY 3/", $response);
@@ -208,4 +217,4 @@ function test_functional_flash()
curl_close($ch);
}
-end_test_case();
+end_test_case();

0 comments on commit 491bbaf

Please sign in to comment.