Skip to content

Commit

Permalink
Refactor functions sending headers to be testable
Browse files Browse the repository at this point in the history
By the way, not sure why one is in functions.php and the other one in functions-html.php ...
  • Loading branch information
ozh committed May 27, 2015
1 parent 6dc180c commit b0e29bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions includes/functions-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ function yourls_new_core_version_notice() {
* @return bool whether header was sent
*/
function yourls_content_type_header( $type ) {
yourls_do_action( 'content_type_header', $type );
if( !headers_sent() ) {
$charset = yourls_apply_filter( 'content_type_header_charset', 'utf-8' );
header( "Content-Type: $type; charset=$charset" );
Expand Down
10 changes: 8 additions & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,15 @@ function yourls_redirect( $location, $code = 301 ) {
/**
* Set HTTP status header
*
* @since 1.4
* @param int $code status header code
* @return bool whether header was sent
*/
function yourls_status_header( $code = 200 ) {
yourls_do_action( 'status_header', $code );

if( headers_sent() )
return;
return false;

$protocol = $_SERVER['SERVER_PROTOCOL'];
if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
Expand All @@ -708,7 +713,8 @@ function yourls_status_header( $code = 200 ) {
$desc = yourls_get_HTTP_status( $code );

@header ("$protocol $code $desc"); // This causes problems on IIS and some FastCGI setups
yourls_do_action( 'status_header', $code );

return true;
}

/**
Expand Down

0 comments on commit b0e29bf

Please sign in to comment.