3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\Logger\LoggerFactory
;
22 use MediaWiki\MediaWikiServices
;
25 * Various HTTP related functions
26 * @deprecated since 1.34
30 /** @deprecated since 1.34, just use the default engine */
31 public static $httpEngine = null;
34 * Perform an HTTP request
36 * @deprecated since 1.34, use HttpRequestFactory::request()
38 * @param string $method HTTP method. Usually GET/POST
39 * @param string $url Full URL to act on. If protocol-relative, will be expanded to an http:// URL
40 * @param array $options Options to pass to MWHttpRequest object. See HttpRequestFactory::create
42 * @param string $caller The method making this request, for profiling
43 * @return string|bool (bool)false on failure or a string on success
45 public static function request( $method, $url, array $options = [], $caller = __METHOD__
) {
46 $ret = MediaWikiServices
::getInstance()->getHttpRequestFactory()->request(
47 $method, $url, $options, $caller );
48 return is_string( $ret ) ?
$ret : false;
52 * Simple wrapper for Http::request( 'GET' )
54 * @deprecated since 1.34, use HttpRequestFactory::get()
56 * @since 1.25 Second parameter $timeout removed. Second parameter
57 * is now $options which can be given a 'timeout'
60 * @param array $options
61 * @param string $caller The method making this request, for profiling
62 * @return string|bool false on error
64 public static function get( $url, array $options = [], $caller = __METHOD__
) {
65 $args = func_get_args();
66 if ( isset( $args[1] ) && ( is_string( $args[1] ) ||
is_numeric( $args[1] ) ) ) {
67 // Second was used to be the timeout
68 // And third parameter used to be $options
69 wfWarn( "Second parameter should not be a timeout.", 2 );
70 $options = isset( $args[2] ) && is_array( $args[2] ) ?
72 $options['timeout'] = $args[1];
75 return self
::request( 'GET', $url, $options, $caller );
79 * Simple wrapper for Http::request( 'POST' )
81 * @deprecated since 1.34, use HttpRequestFactory::post()
84 * @param array $options
85 * @param string $caller The method making this request, for profiling
86 * @return string|bool false on error
88 public static function post( $url, array $options = [], $caller = __METHOD__
) {
89 return self
::request( 'POST', $url, $options, $caller );
93 * A standard user-agent we can use for external requests.
95 * @deprecated since 1.34, use HttpRequestFactory::getUserAgent()
98 public static function userAgent() {
99 return MediaWikiServices
::getInstance()->getHttpRequestFactory()->getUserAgent();
103 * Check that the given URI is a valid one.
105 * This hardcodes a small set of protocols only, because we want to
106 * deterministically reject protocols not supported by all HTTP-transport
109 * "file://" specifically must not be allowed, for security purpose
110 * (see <https://www.mediawiki.org/wiki/Special:Code/MediaWiki/r67684>).
112 * @todo FIXME this is wildly inaccurate and fails to actually check most stuff
114 * @deprecated since 1.34, use MWHttpRequest::isValidURI
115 * @param string $uri URI to check for validity
118 public static function isValidURI( $uri ) {
119 return MWHttpRequest
::isValidURI( $uri );
123 * Gets the relevant proxy from $wgHTTPProxy
125 * @deprecated since 1.34, use $wgHTTPProxy directly
126 * @return string The proxy address or an empty string if not set.
128 public static function getProxy() {
129 wfDeprecated( __METHOD__
, '1.34' );
132 return (string)$wgHTTPProxy;
136 * Get a configured MultiHttpClient
138 * @deprecated since 1.34, construct it directly
139 * @param array $options
140 * @return MultiHttpClient
142 public static function createMultiClient( array $options = [] ) {
143 wfDeprecated( __METHOD__
, '1.34' );
145 global $wgHTTPConnectTimeout, $wgHTTPTimeout, $wgHTTPProxy;
147 return new MultiHttpClient( $options +
[
148 'connTimeout' => $wgHTTPConnectTimeout,
149 'reqTimeout' => $wgHTTPTimeout,
150 'userAgent' => self
::userAgent(),
151 'proxy' => $wgHTTPProxy,
152 'logger' => LoggerFactory
::getInstance( 'http' )