* - followRedirects Whether to follow redirects (defaults to false).
* Note: this should only be used when the target URL is trusted,
* to avoid attacks on intranet services accessible by HTTP.
+ * - userAgent A user agent, if you want to override the default
+ * MediaWiki/$wgVersion
* @return Mixed: (bool)false on failure or a string on success
*/
public static function request( $method, $url, $options = array() ) {
}
$req = MWHttpRequest::factory( $url, $options );
+ if( isset( $options['userAgent'] ) ) {
+ $req->setUserAgent( $options['userAgent'] );
+ }
$status = $req->execute();
if ( $status->isOK() ) {
* Simple wrapper for Http::request( 'GET' )
* @see Http::request()
*
+ * @param $url
+ * @param $timeout string
+ * @param $options array
* @return string
*/
public static function get( $url, $timeout = 'default', $options = array() ) {
* Simple wrapper for Http::request( 'POST' )
* @see Http::request()
*
+ * @param $url
+ * @param $options array
* @return string
*/
public static function post( $url, $options = array() ) {
* protocols, because we only want protocols that both cURL
* and php support.
*
+ * file:// should not be allowed here for security purpose (r67684)
+ *
* @fixme this is wildly inaccurate and fails to actually check most stuff
*
* @param $uri Mixed: URI to check for validity
* Generate a new request object
* @param $url String: url to use
* @param $options Array: (optional) extra params to pass (see Http::request())
+ * @return \CurlHttpRequest|\PhpHttpRequest
* @see MWHttpRequest::__construct
*/
public static function factory( $url, $options = null ) {
/**
* Set the user agent
+ * @param $UA string
*/
public function setUserAgent( $UA ) {
$this->setHeader( 'User-Agent', $UA );
/**
* Set an arbitrary header
+ * @param $name
+ * @param $value
*/
public function setHeader( $name, $value ) {
// I feel like I should normalize the case here...
/**
* Get an array of the headers
+ * @return array
*/
public function getHeaderList() {
$list = array();
* cookies. Used internally after a request to parse the
* Set-Cookie headers.
* @see Cookie::set
+ * @param $name
+ * @param $value null
+ * @param $attr null
*/
public function setCookie( $name, $value = null, $attr = null ) {
if ( !$this->cookieJar ) {
/**
* Returns true if the backend can follow redirects. Overridden by the
* child classes.
+ * @return bool
*/
public function canFollowRedirects() {
return true;
protected $curlOptions = array();
protected $headerText = "";
+ /**
+ * @param $fh
+ * @param $content
+ * @return int
+ */
protected function readHeader( $fh, $content ) {
$this->headerText .= $content;
return strlen( $content );
return $this->status;
}
+ /**
+ * @return bool
+ */
public function canFollowRedirects() {
if ( strval( ini_get( 'open_basedir' ) ) !== '' || wfIniGetBool( 'safe_mode' ) ) {
wfDebug( "Cannot follow redirects in safe mode\n" );
}
class PhpHttpRequest extends MWHttpRequest {
+
+ /**
+ * @param $url string
+ * @return string
+ */
protected function urlToTcp( $url ) {
$parsedUrl = parse_url( $url );
# Check security of URL
$url = $this->getResponseHeader( "Location" );
- if ( substr( $url, 0, 7 ) !== 'http://' ) {
+ if ( !Http::isValidURI( $url ) ) {
wfDebug( __METHOD__ . ": insecure redirection\n" );
break;
}