69 public function create( $url, array $options = [], $caller = __METHOD__ ) {
74 if ( !isset( $options[
'logger'] ) ) {
75 $options[
'logger'] = LoggerFactory::getInstance(
'http' );
86 throw new RuntimeException( __METHOD__ .
': The requested engine is not valid.' );
96 return function_exists(
'curl_init' ) ||
wfIniGetBool(
'allow_url_fopen' );
110 public function request( $method, $url, array $options = [], $caller = __METHOD__ ) {
111 $logger = LoggerFactory::getInstance(
'http' );
112 $logger->debug(
"$method: $url" );
114 $options[
'method'] = strtoupper( $method );
116 if ( !isset( $options[
'timeout'] ) ) {
117 $options[
'timeout'] =
'default';
119 if ( !isset( $options[
'connectTimeout'] ) ) {
120 $options[
'connectTimeout'] =
'default';
123 $req = $this->
create( $url, $options, $caller );
124 $status = $req->execute();
126 if ( $status->isOK() ) {
127 return $req->getContent();
129 $errors = $status->getErrorsByType(
'error' );
130 $logger->warning( Status::wrap( $status )->getWikiText(
false,
false,
'en' ),
131 [
'error' => $errors,
'caller' => $caller,
'content' => $req->getContent() ] );
145 public function get( $url, array $options = [], $caller = __METHOD__ ) {
146 return $this->
request(
'GET', $url, $options, $caller );
158 public function post( $url, array $options = [], $caller = __METHOD__ ) {
159 return $this->
request(
'POST', $url, $options, $caller );
168 return "MediaWiki/$wgVersion";
$wgVersion
MediaWiki version number.
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
MWHttpRequest implemented using internal curl compiled into PHP.
MWHttpRequest implemented using the Guzzle library.
Various HTTP related functions.
This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for h...
Profiler base class that defines the interface and some trivial functionality.
static instance()
Singleton.
Generic operation result class Has warning/error list, boolean status and arbitrary value.