Permalink
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...
Fabrice Luraine
Fabrice Luraine committed May 30, 2011
1 parent 505a058 commit 7316f0f835f56d67f775b4fe485db0fcde223abc
Showing with 24 additions and 11 deletions.
  1. +14 −10 lib/limonade.php
  2. +10 −1 tests/functional.php
View
@@ -443,21 +443,25 @@ function autoload_controller($callback)
function stop_and_exit($exit = true) function stop_and_exit($exit = true)
{ {
call_if_exists('before_exit', $exit); call_if_exists('before_exit', $exit);
$flash_sweep = true;
$headers = headers_list(); $headers = headers_list();
foreach($headers as $header) if(request_is_head())
{ {
// If a Content-Type header exists, flash_sweep only if is text/html ob_end_clean();
// Else if there's no Content-Type header, flash_sweep by default } else {
if(stripos($header, 'Content-Type:') === 0) $flash_sweep = true;
foreach($headers as $header)
{ {
$flash_sweep = stripos($header, 'Content-Type: text/html') === 0; // If a Content-Type header exists, flash_sweep only if is text/html
break; // 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(defined('SID')) session_write_close();
if(request_is_head()) ob_end_clean();
if($exit) exit; if($exit) exit;
} }
View
@@ -184,6 +184,15 @@ function test_functional_flash()
$response = curl_exec($ch); $response = curl_exec($ch);
assert_match("/ON DISPLAY 2/", $response); 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'); curl_setopt($ch, CURLOPT_URL, $path.'three');
$response = curl_exec($ch); $response = curl_exec($ch);
assert_match("/ON DISPLAY 3/", $response); assert_match("/ON DISPLAY 3/", $response);
@@ -208,4 +217,4 @@ function test_functional_flash()
curl_close($ch); curl_close($ch);
} }
end_test_case(); end_test_case();

0 comments on commit 7316f0f

Please sign in to comment.