BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
MWHttpRequest Class Reference
Inheritance diagram for MWHttpRequest:
Collaboration diagram for MWHttpRequest:

Public Member Functions

 __construct ($url, array $options=[], $caller=__METHOD__, $profiler=null)
 
 setLogger (LoggerInterface $logger)
 
 getContent ()
 
 setData ($args)
 
 setUserAgent ($UA)
 
 setHeader ($name, $value)
 
 setCallback ($callback)
 
 read ($fh, $content)
 
 execute ()
 
 getStatus ()
 
 isRedirect ()
 
 getResponseHeaders ()
 
 getResponseHeader ($header)
 
 setCookieJar ($jar)
 
 getCookieJar ()
 
 setCookie ($name, $value, $attr=[])
 
 getFinalUrl ()
 
 canFollowRedirects ()
 
 setOriginalRequest ($originalRequest)
 

Static Public Member Functions

static canMakeRequests ()
 
static factory ($url, array $options=null, $caller=__METHOD__)
 

Public Attributes

const SUPPORTS_FILE_POSTS = false
 

Protected Member Functions

 proxySetup ()
 
 getHeaderList ()
 
 prepare ()
 
 parseHeader ()
 
 setStatus ()
 
 parseCookies ()
 

Protected Attributes

 $timeout = 'default'
 
 $content
 
 $headersOnly = null
 
 $postData = null
 
 $proxy = null
 
 $noProxy = false
 
 $sslVerifyHost = true
 
 $sslVerifyCert = true
 
 $caInfo = null
 
 $method = "GET"
 
 $reqHeaders = []
 
 $url
 
 $parsedUrl
 
 $callback
 
 $maxRedirects = 5
 
 $followRedirects = false
 
 $connectTimeout
 
 $cookieJar
 
 $headerList = []
 
 $respVersion = "0.9"
 
 $respStatus = "200 Ok"
 
 $respHeaders = []
 
 $status
 
 $profiler
 
 $profileName
 
 $logger
 

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.

Constructor & Destructor Documentation

MWHttpRequest::__construct (   $url,
array  $options = [],
  $caller = __METHOD__,
  $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 Http::request())
string$callerThe method making this request, for profiling
Profiler$profilerAn instance of the profiler for profiling, or null

Member Function Documentation

MWHttpRequest::canFollowRedirects ( )

Returns true if the backend can follow redirects. Overridden by the child classes.

Returns
bool
static MWHttpRequest::canMakeRequests ( )
static

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

Returns
bool
MWHttpRequest::execute ( )

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

Returns
StatusValue
Note
currently returns Status for B/C
static MWHttpRequest::factory (   $url,
array  $options = null,
  $caller = __METHOD__ 
)
static

Generate a new request object Deprecated:

See Also
HttpRequestFactory::create
Parameters
string$urlUrl to use
array | null$options(optional) extra params to pass (see Http::request())
string$callerThe method making this request, for profiling
Exceptions
DomainException
Returns
MWHttpRequest
See Also
MWHttpRequest::__construct
MWHttpRequest::getContent ( )

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

Returns
string
MWHttpRequest::getCookieJar ( )

Returns the cookie jar in use.

Returns
CookieJar
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 T31232 is taken care of (high-level redirect handling rewrite).

Returns
string
MWHttpRequest::getHeaderList ( )
protected

Get an array of the headers

Returns
array
MWHttpRequest::getResponseHeader (   $header)

Returns the value of the given response header.

Parameters
string$header
Returns
string|null
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
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
int
MWHttpRequest::isRedirect ( )

Returns true if the last status code was a redirect.

Returns
bool
MWHttpRequest::parseCookies ( )
protected

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

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.

MWHttpRequest::proxySetup ( )
protected

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

Returns
void
MWHttpRequest::read (   $fh,
  $content 
)

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

Parameters
resource$fh
string$content
Returns
int
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
callable | null$callback
Exceptions
InvalidArgumentException
MWHttpRequest::setCookie (   $name,
  $value,
  $attr = [] 
)

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
string$name
string$value
array$attr
MWHttpRequest::setCookieJar (   $jar)

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

To read response cookies from the jar, getCookieJar must be called first.

Parameters
CookieJar$jar
MWHttpRequest::setData (   $args)

Set the parameters of the request

Parameters
array$args
Todo:
overload the args param
MWHttpRequest::setHeader (   $name,
  $value 
)

Set an arbitrary header

Parameters
string$name
string$value
MWHttpRequest::setLogger ( LoggerInterface  $logger)
Parameters
LoggerInterface$logger

Implements Psr\Log\LoggerAwareInterface.

MWHttpRequest::setOriginalRequest (   $originalRequest)

Set information about the original request. This can be useful for endpoints/API modules which act as a proxy for some service, and throttling etc. needs to happen in that service. Calling this will result in the X-Forwarded-For and X-Original-User-Agent headers being set.

Parameters
WebRequest | array$originalRequestWhen in array form, it's expected to have the keys 'ip' and 'userAgent'.
Note
IP/user agent is personally identifiable information, and should only be set when the privacy policy of the request target is compatible with that of the MediaWiki installation.
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.)

MWHttpRequest::setUserAgent (   $UA)

Set the user agent

Parameters
string$UA

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