MediaWiki  1.23.1
MWHttpRequest Class Reference

This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for handling internal HTTP requests. More...

Inheritance diagram for MWHttpRequest:
Collaboration diagram for MWHttpRequest:

Public Member Functions

 canFollowRedirects ()
 Returns true if the backend can follow redirects. More...
 
 execute ()
 Take care of whatever is necessary to perform the URI request. 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...
 
 getHeaderList ()
 Get an array of the headers. 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...
 
 proxySetup ()
 Take care of setting up the proxy (do nothing if "noProxy" is set) More...
 
 read ( $fh, $content)
 A generic callback to read the body of the response from a remote server. More...
 
 setCallback ( $callback)
 Set a read callback to accept data read from the HTTP request. More...
 
 setCookie ( $name, $value=null, $attr=null)
 Sets a cookie. More...
 
 setCookieJar ( $jar)
 Tells the MWHttpRequest object to use this pre-loaded CookieJar. More...
 
 setData ( $args)
 Set the parameters of the request. More...
 
 setHeader ( $name, $value)
 Set an arbitrary header. More...
 
 setUserAgent ( $UA)
 Set the user agent. More...
 

Static Public Member Functions

static canMakeRequests ()
 Simple function to test if we can make any sort of requests at all, using cURL or fopen() More...
 
static factory ( $url, $options=null)
 Generate a new request object. More...
 

Public Attributes

 $status
 
const SUPPORTS_FILE_POSTS = false
 

Protected Member Functions

 __construct ( $url, $options=array())
 
 parseCookies ()
 Parse the cookies in the response headers and store them in the cookie jar. More...
 
 parseHeader ()
 Parses the headers, including the HTTP status code and any Set-Cookie headers. 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 (< 300) or a redirect (>=300 and < 400). More...
 

Protected Attributes

 $caInfo = null
 
 $callback
 
 $content
 
CookieJar $cookieJar
 
 $followRedirects = false
 
 $headerList = array()
 
 $headersOnly = null
 
 $maxRedirects = 5
 
 $method = "GET"
 
 $noProxy = false
 
 $parsedUrl
 
 $postData = null
 
 $proxy = null
 
 $reqHeaders = array()
 
 $respHeaders = array()
 
 $respStatus = "200 Ok"
 
 $respVersion = "0.9"
 
 $sslVerifyCert = true
 
 $sslVerifyHost = true
 
 $timeout = 'default'
 
 $url
 

Detailed Description

This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for handling internal HTTP requests.

Renamed from HttpRequest to MWHttpRequest to avoid conflict with PHP's HTTP extension.

Definition at line 187 of file HttpFunctions.php.

Constructor & Destructor Documentation

◆ __construct()

MWHttpRequest::__construct (   $url,
  $options = array() 
)
protected
Parameters
string$urlurl to use. If protocol-relative, will be expanded to an http:// URL
array$options(optional) extra params to pass (see Http::request())

Definition at line 222 of file HttpFunctions.php.

References $options, $url, array(), as, global, Http\isValidURI(), Status\newFatal(), Status\newGood(), PROTO_HTTP, setUserAgent(), wfExpandUrl(), and wfParseUrl().

Member Function Documentation

◆ canFollowRedirects()

MWHttpRequest::canFollowRedirects ( )

Returns true if the backend can follow redirects.

Overridden by the child classes.

Returns
bool

Reimplemented in CurlHttpRequest.

Definition at line 692 of file HttpFunctions.php.

◆ canMakeRequests()

static MWHttpRequest::canMakeRequests ( )
static

Simple function to test if we can make any sort of requests at all, using cURL or fopen()

Returns
bool

Definition at line 272 of file HttpFunctions.php.

References wfIniGetBool().

Referenced by Installer\subscribeToMediaWikiAnnounce().

◆ execute()

MWHttpRequest::execute ( )

Take care of whatever is necessary to perform the URI request.

Returns
Status

Reimplemented in PhpHttpRequest, and CurlHttpRequest.

Definition at line 435 of file HttpFunctions.php.

References array(), content, proxySetup(), setCallback(), setUserAgent(), Http\userAgent(), wfProfileIn(), and wfProfileOut().

◆ factory()

static MWHttpRequest::factory (   $url,
  $options = null 
)
static

Generate a new request object.

Parameters
string$urlurl to use
array$options(optional) extra params to pass (see Http::request())
Exceptions
MWException
Returns
CurlHttpRequest|PhpHttpRequest
See also
MWHttpRequest::__construct

Reimplemented in MWHttpRequestTester.

Definition at line 284 of file HttpFunctions.php.

References Http\$httpEngine, $options, $url, and wfIniGetBool().

Referenced by ForeignAPIRepo\httpGet(), SpecialUploadStash\outputRemoteScaledThumb(), UploadFromUrl\reallyFetchFile(), Http\request(), Installer\subscribeToMediaWikiAnnounce(), and ApiLoginTest\testApiLoginGotCookie().

◆ getContent()

MWHttpRequest::getContent ( )

Get the body, or content, of the response to the request.

Returns
String

Definition at line 314 of file HttpFunctions.php.

References $content.

◆ getCookieJar()

MWHttpRequest::getCookieJar ( )

Returns the cookie jar in use.

Returns
CookieJar

Definition at line 587 of file HttpFunctions.php.

References $cookieJar, and parseHeader().

◆ getFinalUrl()

MWHttpRequest::getFinalUrl ( )

Returns the final URL after all redirections.

Relative values of the "Location" header are incorrect as stated in RFC, however they do happen and modern browsers support them. This function loops backwards through all locations in order to build the proper absolute URI - Marooned at wikia-inc.com

Note that the multiple Location: headers are an artifact of CURL – they shouldn't actually get returned this way. Rewrite this when bug 29232 is taken care of (high-level redirect handling rewrite).

Returns
string

Definition at line 648 of file HttpFunctions.php.

References $url, and getResponseHeaders().

Referenced by parseCookies().

◆ getHeaderList()

MWHttpRequest::getHeaderList ( )

Get an array of the headers.

Returns
array

Definition at line 374 of file HttpFunctions.php.

References $name, $value, array(), and as.

Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().

◆ getResponseHeader()

MWHttpRequest::getResponseHeader (   $header)

Returns the value of the given response header.

Parameters
$headerString
Returns
String

Definition at line 560 of file HttpFunctions.php.

References parseHeader().

Referenced by PhpHttpRequest\execute().

◆ getResponseHeaders()

MWHttpRequest::getResponseHeaders ( )

Returns an associative array of response headers after the request has been executed.

Because some headers (e.g. Set-Cookie) can appear more than once the, each value of the associative array is an array of the values given.

Returns
Array

Definition at line 546 of file HttpFunctions.php.

References $respHeaders, and parseHeader().

Referenced by getFinalUrl().

◆ getStatus()

MWHttpRequest::getStatus ( )

Get the integer value of the HTTP status code (e.g.

200 for "200 Ok") (see RFC2616, section 10, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for a list of status codes.)

Returns
Integer

Definition at line 511 of file HttpFunctions.php.

References $respStatus, and parseHeader().

◆ isRedirect()

MWHttpRequest::isRedirect ( )

Returns true if the last status code was a redirect.

Returns
Boolean

Definition at line 524 of file HttpFunctions.php.

References $status, and parseHeader().

Referenced by PhpHttpRequest\execute().

◆ parseCookies()

MWHttpRequest::parseCookies ( )
protected

Parse the cookies in the response headers and store them in the cookie jar.

Definition at line 615 of file HttpFunctions.php.

References $url, as, getFinalUrl(), wfProfileIn(), and wfProfileOut().

Referenced by parseHeader().

◆ parseHeader()

MWHttpRequest::parseHeader ( )
protected

Parses the headers, including the HTTP status code and any Set-Cookie headers.

This function expects the headers to be found in an array in the member variable headerList.

Definition at line 462 of file HttpFunctions.php.

References $last, as, parseCookies(), wfProfileIn(), and wfProfileOut().

Referenced by CurlHttpRequest\execute(), PhpHttpRequest\execute(), getCookieJar(), getResponseHeader(), getResponseHeaders(), getStatus(), isRedirect(), and setStatus().

◆ proxySetup()

MWHttpRequest::proxySetup ( )

Take care of setting up the proxy (do nothing if "noProxy" is set)

Returns
void

Definition at line 333 of file HttpFunctions.php.

References global, and Http\isLocalURL().

Referenced by execute().

◆ read()

MWHttpRequest::read (   $fh,
  $content 
)

A generic callback to read the body of the response from a remote server.

Parameters
$fhhandle
$contentString
Returns
int

Definition at line 425 of file HttpFunctions.php.

References $content, and content.

◆ setCallback()

MWHttpRequest::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.

Parameters
$callbackCallback
Exceptions
MWException

Definition at line 410 of file HttpFunctions.php.

References $callback.

Referenced by execute().

◆ setCookie()

MWHttpRequest::setCookie (   $name,
  $value = null,
  $attr = null 
)

Sets a cookie.

Used before a request to set up any individual cookies. Used internally after a request to parse the Set-Cookie headers.

See also
Cookie::set
Parameters
$name
$valuenull
$attrnull

Definition at line 604 of file HttpFunctions.php.

References $name, $value, and CookieJar\setCookie().

◆ setCookieJar()

MWHttpRequest::setCookieJar (   $jar)

Tells the MWHttpRequest object to use this pre-loaded CookieJar.

Parameters
$jarCookieJar

Definition at line 578 of file HttpFunctions.php.

◆ setData()

MWHttpRequest::setData (   $args)

Set the parameters of the request.

Parameters
$argsArray
Todo:
overload the args param

Definition at line 324 of file HttpFunctions.php.

References $args.

◆ setHeader()

MWHttpRequest::setHeader (   $name,
  $value 
)

Set an arbitrary header.

Parameters
$name
$value

Definition at line 365 of file HttpFunctions.php.

References $name, and $value.

Referenced by setUserAgent().

◆ setStatus()

MWHttpRequest::setStatus ( )
protected

Sets HTTPRequest status member to a fatal value with the error message if the returned integer value of the status code was not successful (< 300) or a redirect (>=300 and < 400).

(see RFC2616, section 10, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for a list of status codes.)

Definition at line 493 of file HttpFunctions.php.

References list, and parseHeader().

Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().

◆ setUserAgent()

MWHttpRequest::setUserAgent (   $UA)

Set the user agent.

Parameters
$UAstring

Definition at line 356 of file HttpFunctions.php.

References setHeader().

Referenced by __construct(), and execute().

Member Data Documentation

◆ $caInfo

MWHttpRequest::$caInfo = null
protected

Definition at line 198 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().

◆ $callback

MWHttpRequest::$callback
protected

Definition at line 203 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute(), and setCallback().

◆ $content

MWHttpRequest::$content
protected

Definition at line 190 of file HttpFunctions.php.

Referenced by getContent(), read(), and CurlHttpRequest\readHeader().

◆ $cookieJar

CookieJar MWHttpRequest::$cookieJar
protected

Definition at line 209 of file HttpFunctions.php.

Referenced by getCookieJar().

◆ $followRedirects

MWHttpRequest::$followRedirects = false
protected

Definition at line 205 of file HttpFunctions.php.

◆ $headerList

MWHttpRequest::$headerList = array()
protected

Definition at line 211 of file HttpFunctions.php.

◆ $headersOnly

MWHttpRequest::$headersOnly = null
protected

Definition at line 192 of file HttpFunctions.php.

◆ $maxRedirects

MWHttpRequest::$maxRedirects = 5
protected

Definition at line 204 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute().

◆ $method

MWHttpRequest::$method = "GET"
protected

Definition at line 199 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute().

◆ $noProxy

MWHttpRequest::$noProxy = false
protected

Definition at line 195 of file HttpFunctions.php.

◆ $parsedUrl

MWHttpRequest::$parsedUrl
protected

Definition at line 202 of file HttpFunctions.php.

Referenced by PhpHttpRequest\urlToTcp().

◆ $postData

MWHttpRequest::$postData = null
protected

Definition at line 193 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().

◆ $proxy

MWHttpRequest::$proxy = null
protected

Definition at line 194 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute().

◆ $reqHeaders

MWHttpRequest::$reqHeaders = array()
protected

Definition at line 200 of file HttpFunctions.php.

◆ $respHeaders

MWHttpRequest::$respHeaders = array()
protected

Definition at line 214 of file HttpFunctions.php.

Referenced by getResponseHeaders().

◆ $respStatus

MWHttpRequest::$respStatus = "200 Ok"
protected

Definition at line 213 of file HttpFunctions.php.

Referenced by getStatus().

◆ $respVersion

MWHttpRequest::$respVersion = "0.9"
protected

Definition at line 212 of file HttpFunctions.php.

◆ $sslVerifyCert

MWHttpRequest::$sslVerifyCert = true
protected

Definition at line 197 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute().

◆ $sslVerifyHost

MWHttpRequest::$sslVerifyHost = true
protected

Definition at line 196 of file HttpFunctions.php.

◆ $status

MWHttpRequest::$status

Definition at line 216 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute(), PhpHttpRequest\execute(), and isRedirect().

◆ $timeout

MWHttpRequest::$timeout = 'default'
protected

Definition at line 191 of file HttpFunctions.php.

Referenced by CurlHttpRequest\execute().

◆ $url

◆ SUPPORTS_FILE_POSTS

const MWHttpRequest::SUPPORTS_FILE_POSTS = false

Definition at line 188 of file HttpFunctions.php.


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