/**
* @param string $url Url to use. If protocol-relative, will be expanded to an http:// URL
- * @param array $options (optional) extra params to pass (see Http::request())
+ * @param array $options (optional) extra params to pass (see HttpRequestFactory::create())
* @param string $caller The method making this request, for profiling
* @param Profiler|null $profiler An instance of the profiler for profiling, or null
* @throws Exception
*/
public function __construct(
- $url, array $options = [], $caller = __METHOD__, $profiler = null
+ $url, array $options = [], $caller = __METHOD__, Profiler $profiler = null
) {
global $wgHTTPTimeout, $wgHTTPConnectTimeout;
$this->setOriginalRequest( $options['originalRequest'] );
}
+ $this->setHeader( 'X-Request-Id', WebRequest::getRequestId() );
+
$members = [ "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo",
"method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback" ];
/**
* Generate a new request object
- * Deprecated: @see HttpRequestFactory::create
+ * @deprecated since 1.34, use HttpRequestFactory instead
* @param string $url Url to use
- * @param array|null $options (optional) extra params to pass (see Http::request())
+ * @param array|null $options (optional) extra params to pass (see HttpRequestFactory::create())
* @param string $caller The method making this request, for profiling
* @throws DomainException
* @return MWHttpRequest
* @param array $args
* @todo overload the args param
*/
- public function setData( $args ) {
+ public function setData( array $args ) {
$this->postData = $args;
}
if ( self::isLocalURL( $this->url ) || $this->noProxy ) {
$this->proxy = '';
} else {
- $this->proxy = Http::getProxy();
+ global $wgHTTPProxy;
+ $this->proxy = (string)$wgHTTPProxy;
}
}
* @throws InvalidArgumentException
*/
public function setCallback( $callback ) {
+ return $this->doSetCallback( $callback );
+ }
+
+ /**
+ * Worker function for setting callbacks. Calls can originate both internally and externally
+ * via setCallback). Defaults to the internal read callback if $callback is null.
+ *
+ * @param callable|null $callback
+ * @throws InvalidArgumentException
+ */
+ protected function doSetCallback( $callback ) {
if ( is_null( $callback ) ) {
$callback = [ $this, 'read' ];
} elseif ( !is_callable( $callback ) ) {
$this->proxySetup(); // set up any proxy as needed
if ( !$this->callback ) {
- $this->setCallback( null );
+ $this->doSetCallback( null );
}
if ( !isset( $this->reqHeaders['User-Agent'] ) ) {
*
* @param CookieJar $jar
*/
- public function setCookieJar( $jar ) {
+ public function setCookieJar( CookieJar $jar ) {
$this->cookieJar = $jar;
}
* @param string $value
* @param array $attr
*/
- public function setCookie( $name, $value, $attr = [] ) {
+ public function setCookie( $name, $value, array $attr = [] ) {
if ( !$this->cookieJar ) {
$this->cookieJar = new CookieJar;
}
$this->reqHeaders['X-Forwarded-For'] = $originalRequest['ip'];
$this->reqHeaders['X-Original-User-Agent'] = $originalRequest['userAgent'];
}
+
+ /**
+ * Check that the given URI is a valid one.
+ *
+ * This hardcodes a small set of protocols only, because we want to
+ * deterministically reject protocols not supported by all HTTP-transport
+ * methods.
+ *
+ * "file://" specifically must not be allowed, for security reasons
+ * (see <https://www.mediawiki.org/wiki/Special:Code/MediaWiki/r67684>).
+ *
+ * @todo FIXME this is wildly inaccurate and fails to actually check most stuff
+ *
+ * @since 1.34
+ * @param string $uri URI to check for validity
+ * @return bool
+ */
+ public static function isValidURI( $uri ) {
+ return (bool)preg_match(
+ '/^https?:\/\/[^\/\s]\S*$/D',
+ $uri
+ );
+ }
}