* Don't create a WebRequest obhject in CLI mode but a FauxRequest; avoids some useless notices about headers already sent (I know this is more a PHP silliness, but anyway)
* Added HTTP response code parsing (sending a "HTTP/1.x code" header was throwing a NOTICE about undefined index on the result of the explode() call) and storage; added FauxResponse::getStatusCode() to retrieve it
This commit is contained in:
parent
c75465b7ad
commit
2f7f99b1f1
2 changed files with 27 additions and 6 deletions
|
|
@ -364,14 +364,16 @@ if( is_null( $wgLocalTZoffset ) ) {
|
|||
$wgLocalTZoffset = date( 'Z' ) / 60;
|
||||
}
|
||||
|
||||
# Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
|
||||
$wgRequest = new WebRequest;
|
||||
|
||||
# Useful debug output
|
||||
global $wgCommandLineMode;
|
||||
if ( $wgCommandLineMode ) {
|
||||
$wgRequest = new FauxRequest( array() );
|
||||
|
||||
wfDebug( "\n\nStart command line script $self\n" );
|
||||
} else {
|
||||
# Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
|
||||
$wgRequest = new WebRequest;
|
||||
|
||||
$debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
|
||||
|
||||
if ( $wgDebugPrintHttpHeaders ) {
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ class WebResponse {
|
|||
class FauxResponse extends WebResponse {
|
||||
private $headers;
|
||||
private $cookies;
|
||||
private $code;
|
||||
|
||||
/**
|
||||
* Stores a HTTP header
|
||||
|
|
@ -85,10 +86,19 @@ class FauxResponse extends WebResponse {
|
|||
* @param $http_response_code null|int Forces the HTTP response code to the specified value.
|
||||
*/
|
||||
public function header( $string, $replace = true, $http_response_code = null ) {
|
||||
list( $key, $val ) = explode( ":", $string, 2 );
|
||||
$match = array();
|
||||
if ( preg_match( '~^HTTP/1.\d (\d+)\D*$~', $string, $match ) ) {
|
||||
$this->code = intval( $match[1] );
|
||||
} else {
|
||||
list( $key, $val ) = explode( ":", $string, 2 );
|
||||
|
||||
if( $replace || !isset( $this->headers[$key] ) ) {
|
||||
$this->headers[$key] = $val;
|
||||
if( $replace || !isset( $this->headers[$key] ) ) {
|
||||
$this->headers[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $http_response_code !== null ) {
|
||||
$this->code = intval( $http_response_code );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,6 +110,15 @@ class FauxResponse extends WebResponse {
|
|||
return $this->headers[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP response code, null if not set
|
||||
*
|
||||
* @return Int or null
|
||||
*/
|
||||
public function getStatusCode() {
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name String: name of cookie
|
||||
* @param $value String: value to give cookie
|
||||
|
|
|
|||
Loading…
Reference in a new issue