MediaWiki  master
GuzzleHttpRequest Class Reference

MWHttpRequest implemented using the Guzzle library. More...

Inheritance diagram for GuzzleHttpRequest:
Collaboration diagram for GuzzleHttpRequest:

Public Member Functions

 __construct ( $url, array $options=[], $caller=__METHOD__, Profiler $profiler=null)
 
 execute ()
 
 setCallback ( $callback)
 Set a read callback to accept data read from the HTTP request. More...
 
- Public Member Functions inherited from MWHttpRequest
 canFollowRedirects ()
 Returns true if the backend can follow redirects. More...
 
 getContent ()
 Get the body, or content, of the response to the request. More...
 
 getCookieJar ()
 Returns the cookie jar in use. More...
 
 getFinalUrl ()
 Returns the final URL after all redirections. More...
 
 getResponseHeader ( $header)
 Returns the value of the given response header. More...
 
 getResponseHeaders ()
 Returns an associative array of response headers after the request has been executed. More...
 
 getStatus ()
 Get the integer value of the HTTP status code (e.g. More...
 
 isRedirect ()
 Returns true if the last status code was a redirect. More...
 
 read ( $fh, $content)
 A generic callback to read the body of the response from a remote server. More...
 
 setCookie ( $name, $value, array $attr=[])
 Sets a cookie. More...
 
 setCookieJar (CookieJar $jar)
 Tells the MWHttpRequest object to use this pre-loaded CookieJar. More...
 
 setData (array $args)
 Set the parameters of the request. More...
 
 setHeader ( $name, $value)
 Set an arbitrary header. More...
 
 setLogger (LoggerInterface $logger)
 
 setOriginalRequest ( $originalRequest)
 Set information about the original request. More...
 
 setUserAgent ( $UA)
 Set the user agent. More...
 

Public Attributes

const SUPPORTS_FILE_POSTS = true
 
- Public Attributes inherited from MWHttpRequest
const SUPPORTS_FILE_POSTS = false
 

Protected Member Functions

 doSetCallback ( $callback)
 Worker function for setting callbacks. More...
 
 parseHeader ()
 Guzzle provides headers as an array. More...
 
 prepare ()
 
 usingCurl ()
 
- Protected Member Functions inherited from MWHttpRequest
 getHeaderList ()
 Get an array of the headers. More...
 
 parseCookies ()
 Parse the cookies in the response headers and store them in the cookie jar. More...
 
 proxySetup ()
 Take care of setting up the proxy (do nothing if "noProxy" is set) More...
 
 setStatus ()
 Sets HTTPRequest status member to a fatal value with the error message if the returned integer value of the status code was not successful (1-299) or a redirect (300-399). More...
 

Protected Attributes

array $guzzleOptions = [ 'http_errors' => false ]
 
 $handler = null
 
 $sink = null
 
- Protected Attributes inherited from MWHttpRequest
 $caInfo = null
 
callable $callback
 
 $connectTimeout
 
 $content
 
CookieJar $cookieJar
 
 $followRedirects = false
 
 $headerList = []
 
 $headersOnly = null
 
LoggerInterface $logger
 
 $maxRedirects = 5
 
 $method = "GET"
 
 $noProxy = false
 
 $parsedUrl
 
 $postData = null
 
string $profileName
 
Profiler $profiler
 
 $proxy = null
 
array $reqHeaders = []
 
string[][] $respHeaders = []
 
 $respStatus = "200 Ok"
 
 $respVersion = "0.9"
 
 $sslVerifyCert = true
 
 $sslVerifyHost = true
 
StatusValue $status
 
int string $timeout = 'default'
 
 $url
 

Additional Inherited Members

- Static Public Member Functions inherited from MWHttpRequest
static canMakeRequests ()
 Simple function to test if we can make any sort of requests at all, using cURL or fopen() More...
 
static factory ( $url, array $options=null, $caller=__METHOD__)
 Generate a new request object. More...
 
static isValidURI ( $uri)
 Check that the given URI is a valid one. More...
 

Detailed Description

MWHttpRequest implemented using the Guzzle library.

Differences from the CurlHttpRequest implementation: 1) a new 'sink' option is available as an alternative to callbacks. See: http://docs.guzzlephp.org/en/stable/request-options.html#sink) The 'callback' option remains available as well. If both 'sink' and 'callback' are specified, 'sink' is used. 2) callers may set a custom handler via the 'handler' option. If this is not set, Guzzle will use curl (if available) or PHP streams (otherwise) 3) setting either sslVerifyHost or sslVerifyCert will enable both. Guzzle does not allow them to be set separately.

Since
1.33

Definition at line 39 of file GuzzleHttpRequest.php.

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttpRequest::__construct (   $url,
array  $options = [],
  $caller = __METHOD__,
Profiler  $profiler = null 
)
Parameters
string$urlUrl to use. If protocol-relative, will be expanded to an http:// URL
array$options(optional) extra params to pass (see HttpRequestFactory::create())
string$callerThe method making this request, for profiling
Profiler | null$profilerAn instance of the profiler for profiling, or null
Exceptions
Exception

Reimplemented from MWHttpRequest.

Definition at line 54 of file GuzzleHttpRequest.php.

References MWHttpRequest\$profiler, and MWHttpRequest\$url.

Member Function Documentation

◆ doSetCallback()

GuzzleHttpRequest::doSetCallback (   $callback)
protected

Worker function for setting callbacks.

Calls can originate both internally and externally via setCallback). Defaults to the internal read callback if $callback is null.

If a sink is already specified, this does nothing. This causes the 'sink' constructor option to override the 'callback' constructor option.

Parameters
callable | null$callback
Exceptions
InvalidArgumentException

Reimplemented from MWHttpRequest.

Definition at line 102 of file GuzzleHttpRequest.php.

References MWHttpRequest\$callback.

Referenced by prepare(), and setCallback().

◆ execute()

◆ parseHeader()

GuzzleHttpRequest::parseHeader ( )
protected

Guzzle provides headers as an array.

Reprocess to match our expectations. Guzzle will have already parsed and removed the status line (in EasyHandle::createResponse).

Reimplemented from MWHttpRequest.

Definition at line 246 of file GuzzleHttpRequest.php.

References MWHttpRequest\parseCookies().

Referenced by execute().

◆ prepare()

GuzzleHttpRequest::prepare ( )
protected

Reimplemented from MWHttpRequest.

Definition at line 229 of file GuzzleHttpRequest.php.

References doSetCallback().

Referenced by execute().

◆ setCallback()

GuzzleHttpRequest::setCallback (   $callback)

Set a read callback to accept data read from the HTTP request.

By default, data is appended to an internal buffer which can be retrieved through $req->getContent().

To handle data as it comes in – especially for large files that would not fit in memory – you can instead set your own callback, in the form function($resource, $buffer) where the first parameter is the low-level resource being read (implementation specific), and the second parameter is the data buffer.

You MUST return the number of bytes handled in the buffer; if fewer bytes are reported handled than were passed to you, the HTTP fetch will be aborted.

This function overrides any 'sink' or 'callback' constructor option.

Parameters
callable | null$callback
Exceptions
InvalidArgumentException

Reimplemented from MWHttpRequest.

Definition at line 87 of file GuzzleHttpRequest.php.

References MWHttpRequest\$callback, and doSetCallback().

◆ usingCurl()

GuzzleHttpRequest::usingCurl ( )
protected
Returns
bool

Definition at line 237 of file GuzzleHttpRequest.php.

Referenced by execute().

Member Data Documentation

◆ $guzzleOptions

array GuzzleHttpRequest::$guzzleOptions = [ 'http_errors' => false ]
protected

Definition at line 45 of file GuzzleHttpRequest.php.

◆ $handler

GuzzleHttpRequest::$handler = null
protected

Definition at line 42 of file GuzzleHttpRequest.php.

Referenced by execute().

◆ $sink

GuzzleHttpRequest::$sink = null
protected

Definition at line 43 of file GuzzleHttpRequest.php.

Referenced by execute().

◆ SUPPORTS_FILE_POSTS

const GuzzleHttpRequest::SUPPORTS_FILE_POSTS = true

Definition at line 40 of file GuzzleHttpRequest.php.


The documentation for this class was generated from the following file: