MediaWiki  REL1_19
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:

List of all members.

Public Member Functions

 __construct ($url, $options=array())
 canFollowRedirects ()
 Returns true if the backend can follow redirects.
 execute ()
 Take care of whatever is necessary to perform the URI request.
 getContent ()
 Get the body, or content, of the response to the request.
 getCookieJar ()
 Returns the cookie jar in use.
 getFinalUrl ()
 Returns the final URL after all redirections.
 getHeaderList ()
 Get an array of the headers.
 getResponseHeader ($header)
 Returns the value of the given response header.
 getResponseHeaders ()
 Returns an associative array of response headers after the request has been executed.
 getStatus ()
 Get the integer value of the HTTP status code (e.g.
 isRedirect ()
 Returns true if the last status code was a redirect.
 proxySetup ()
 Take care of setting up the proxy (override in subclass)
 read ($fh, $content)
 A generic callback to read the body of the response from a remote server.
 setCallback ($callback)
 Set a read callback to accept data read from the HTTP request.
 setCookie ($name, $value=null, $attr=null)
 Sets a cookie.
 setCookieJar ($jar)
 Tells the MWHttpRequest object to use this pre-loaded CookieJar.
 setData ($args)
 Set the parameters of the request.
 setHeader ($name, $value)
 Set an arbitrary header.
 setReferer ($url)
 Set the refererer header.
 setUserAgent ($UA)
 Set the user agent.

Static Public Member Functions

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

Public Attributes

 $status
const SUPPORTS_FILE_POSTS = false

Protected Member Functions

 parseCookies ()
 Parse the cookies in the response headers and store them in the cookie jar.
 parseHeader ()
 Parses the headers, including the HTTP status code and any Set-Cookie headers.
 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).

Protected Attributes

 $caInfo = null
 $callback
 $content
 $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 159 of file HttpFunctions.php.


Constructor & Destructor Documentation

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

Definition at line 195 of file HttpFunctions.php.

References $options, $url, $wgHTTPTimeout, Http\isValidURI(), Status\newFatal(), Status\newGood(), wfExpandUrl(), and wfParseUrl().

Here is the call graph for this function:


Member Function Documentation

Returns true if the backend can follow redirects.

Overridden by the child classes.

Returns:
bool

Reimplemented in CurlHttpRequest.

Definition at line 643 of file HttpFunctions.php.

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 228 of file HttpFunctions.php.

References wfIniGetBool().

Referenced by Installer\subscribeToMediaWikiAnnounce().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Returns:
Status

Reimplemented in PhpHttpRequest, and CurlHttpRequest.

Definition at line 390 of file HttpFunctions.php.

References $wgTitle, proxySetup(), setCallback(), setReferer(), setUserAgent(), Http\userAgent(), and wfExpandUrl().

Here is the call graph for this function:

static MWHttpRequest::factory ( url,
options = null 
) [static]

Generate a new request object.

Parameters:
$urlString: url to use
$optionsArray: (optional) extra params to pass (see Http::request())
Returns:
CurlHttpRequest|PhpHttpRequest
See also:
MWHttpRequest::__construct

Definition at line 239 of file HttpFunctions.php.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Returns:
String

Definition at line 266 of file HttpFunctions.php.

Returns the cookie jar in use.

Returns:
CookieJar

Definition at line 547 of file HttpFunctions.php.

References parseHeader().

Here is the call graph for this function:

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 600 of file HttpFunctions.php.

References $url, and getResponseHeaders().

Referenced by parseCookies().

Here is the call graph for this function:

Here is the caller graph for this function:

Get an array of the headers.

Returns:
array

Definition at line 331 of file HttpFunctions.php.

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

Here is the caller graph for this function:

Returns the value of the given response header.

Parameters:
$headerString
Returns:
String

Definition at line 520 of file HttpFunctions.php.

References parseHeader().

Referenced by PhpHttpRequest\execute().

Here is the call graph for this function:

Here is the caller graph for this function:

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 506 of file HttpFunctions.php.

References parseHeader().

Referenced by getFinalUrl().

Here is the call graph for this function:

Here is the caller graph for this function:

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 470 of file HttpFunctions.php.

References parseHeader().

Here is the call graph for this function:

Returns true if the last status code was a redirect.

Returns:
Boolean

Definition at line 484 of file HttpFunctions.php.

References $status, and parseHeader().

Referenced by PhpHttpRequest\execute().

Here is the call graph for this function:

Here is the caller graph for this function:

MWHttpRequest::parseCookies ( ) [protected]

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

Definition at line 575 of file HttpFunctions.php.

References $url, and getFinalUrl().

Referenced by parseHeader().

Here is the call graph for this function:

Here is the caller graph for this function:

MWHttpRequest::parseHeader ( ) [protected]

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

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

Returns:
nothing

Definition at line 423 of file HttpFunctions.php.

References parseCookies().

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

Here is the call graph for this function:

Here is the caller graph for this function:

Take care of setting up the proxy (override in subclass)

Returns:
String

Definition at line 286 of file HttpFunctions.php.

References $wgHTTPProxy, and Http\isLocalURL().

Referenced by execute().

Here is the call graph for this function:

Here is the caller graph for this function:

MWHttpRequest::read ( fh,
content 
)

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

Parameters:
$fhhandle
$contentString

Definition at line 380 of file HttpFunctions.php.

References $content.

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

Definition at line 366 of file HttpFunctions.php.

References $callback.

Referenced by execute().

Here is the caller graph for this function:

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 564 of file HttpFunctions.php.

References CookieJar\setCookie().

Here is the call graph for this function:

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

Parameters:
$jarCookieJar

Definition at line 538 of file HttpFunctions.php.

Set the parameters of the request.

Parameters:
$argsArray
Todo:
overload the args param

Definition at line 276 of file HttpFunctions.php.

MWHttpRequest::setHeader ( name,
value 
)

Set an arbitrary header.

Parameters:
$name
$value

Definition at line 322 of file HttpFunctions.php.

Referenced by setReferer(), and setUserAgent().

Here is the caller graph for this function:

Set the refererer header.

Definition at line 305 of file HttpFunctions.php.

References $url, and setHeader().

Referenced by execute().

Here is the call graph for this function:

Here is the caller graph for this function:

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.)

Returns:
nothing

Definition at line 452 of file HttpFunctions.php.

References parseHeader().

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

Here is the call graph for this function:

Here is the caller graph for this function:

Set the user agent.

Parameters:
$UAstring

Definition at line 313 of file HttpFunctions.php.

References setHeader().

Referenced by execute().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

MWHttpRequest::$caInfo = null [protected]

Definition at line 170 of file HttpFunctions.php.

MWHttpRequest::$callback [protected]

Definition at line 175 of file HttpFunctions.php.

Referenced by setCallback().

MWHttpRequest::$content [protected]

Definition at line 162 of file HttpFunctions.php.

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

MWHttpRequest::$cookieJar [protected]

Definition at line 182 of file HttpFunctions.php.

MWHttpRequest::$followRedirects = false [protected]

Definition at line 177 of file HttpFunctions.php.

MWHttpRequest::$headerList = array() [protected]

Definition at line 184 of file HttpFunctions.php.

MWHttpRequest::$headersOnly = null [protected]

Definition at line 164 of file HttpFunctions.php.

MWHttpRequest::$maxRedirects = 5 [protected]

Definition at line 176 of file HttpFunctions.php.

MWHttpRequest::$method = "GET" [protected]

Definition at line 171 of file HttpFunctions.php.

MWHttpRequest::$noProxy = false [protected]

Definition at line 167 of file HttpFunctions.php.

MWHttpRequest::$parsedUrl [protected]

Definition at line 174 of file HttpFunctions.php.

Referenced by PhpHttpRequest\urlToTcp().

MWHttpRequest::$postData = null [protected]

Definition at line 165 of file HttpFunctions.php.

MWHttpRequest::$proxy = null [protected]

Definition at line 166 of file HttpFunctions.php.

MWHttpRequest::$reqHeaders = array() [protected]

Definition at line 172 of file HttpFunctions.php.

MWHttpRequest::$respHeaders = array() [protected]

Definition at line 187 of file HttpFunctions.php.

MWHttpRequest::$respStatus = "200 Ok" [protected]

Definition at line 186 of file HttpFunctions.php.

MWHttpRequest::$respVersion = "0.9" [protected]

Definition at line 185 of file HttpFunctions.php.

MWHttpRequest::$sslVerifyCert = true [protected]

Definition at line 169 of file HttpFunctions.php.

MWHttpRequest::$sslVerifyHost = true [protected]

Definition at line 168 of file HttpFunctions.php.

MWHttpRequest::$status

Definition at line 189 of file HttpFunctions.php.

Referenced by isRedirect().

MWHttpRequest::$timeout = 'default' [protected]

Definition at line 163 of file HttpFunctions.php.

MWHttpRequest::$url [protected]

Reimplemented in CurlHttpRequest.

Definition at line 160 of file HttpFunctions.php.


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