*
* @param $method String: HTTP method. Usually GET/POST
* @param $url String: full URL to act on
- * @param $options Array: options to pass to HttpRequest object.
+ * @param $options Array: options to pass to MWHttpRequest object.
* Possible keys for the array:
* - timeout Timeout length in seconds
* - postData An array of key-value pairs or a url-encoded form data
$options['timeout'] = 'default';
}
- $req = HttpRequest::factory( $url, $options );
+ $req = MWHttpRequest::factory( $url, $options );
$status = $req->execute();
if ( $status->isOK() ) {
/**
* This wrapper class will call out to curl (if available) or fallback
* to regular PHP if necessary for handling internal HTTP requests.
+ *
+ * Renamed from HttpRequest to MWHttpRequst to avoid conflict with
+ * php's HTTP extension.
*/
-class HttpRequest {
+class MWHttpRequest {
protected $content;
protected $timeout = 'default';
protected $headersOnly = null;
/**
* Generate a new request object
- * @see HttpRequest::__construct
+ * @see MWHttpRequest::__construct
*/
public static function factory( $url, $options = null ) {
if ( !Http::$httpEngine ) {
}
/**
- * Sets the member variable status to a fatal status if the HTTP
- * status code was not 200.
+ * Sets HTTPRequest status member to a fatal value with the error
+ * message if the returned integer value of the status code was
+ * not successful (< 300) or a redirect (>=300 and < 400). (see
+ * RFC2616, section 10,
+ * http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for a
+ * list of status codes.)
*
* @return nothing
*/
$this->parseHeader();
}
- if ( (int)$this->respStatus !== 200 ) {
+ if ( (int)$this->respStatus > 399 ) {
list( $code, $message ) = explode( " ", $this->respStatus, 2 );
$this->status->fatal( "http-bad-status", $code, $message );
}
}
+ /**
+ * Get the integer value of the HTTP status code (e.g. 200 for "200 Ok")
+ * (see RFC2616, section 10, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
+ * for a list of status codes.)
+ *
+ * @return Integer
+ */
+ public function getStatus() {
+ if ( !$this->respHeaders ) {
+ $this->parseHeader();
+ }
+
+ return (int)$this->respStatus;
+ }
+
/**
* Returns true if the last status code was a redirect.
}
/**
- * Tells the HttpRequest object to use this pre-loaded CookieJar.
+ * Tells the MWHttpRequest object to use this pre-loaded CookieJar.
*
* @param $jar CookieJar
*/
}
/**
- * HttpRequest implemented using internal curl compiled into PHP
+ * MWHttpRequest implemented using internal curl compiled into PHP
*/
-class CurlHttpRequest extends HttpRequest {
+class CurlHttpRequest extends MWHttpRequest {
static $curlMessageMap = array(
6 => 'http-host-unreachable',
28 => 'http-timed-out'
}
if ( $this->followRedirects && $this->canFollowRedirects() ) {
- if ( ! @curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION, true ) ) {
+ wfSuppressWarnings();
+ if ( ! curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION, true ) ) {
wfDebug( __METHOD__ . ": Couldn't set CURLOPT_FOLLOWLOCATION. " .
"Probably safe_mode or open_basedir is set.\n" );
// Continue the processing. If it were in curl_setopt_array,
// processing would have halted on its entry
}
+ wfRestoreWarnings();
}
if ( false === curl_exec( $curlHandle ) ) {
}
}
-class PhpHttpRequest extends HttpRequest {
+class PhpHttpRequest extends MWHttpRequest {
protected function urlToTcp( $url ) {
$parsedUrl = parse_url( $url );