MediaWiki
1.28.0
|
This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for handling internal HTTP requests. More...
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... | |
setLogger (LoggerInterface $logger) | |
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, $caller=__METHOD__) |
Generate a new request object. More... | |
Public Attributes | |
$logger | |
$status | |
const | SUPPORTS_FILE_POSTS = false |
Protected Member Functions | |
__construct ($url, $options=[], $caller=__METHOD__, $profiler=null) | |
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 = [] | |
$headersOnly = null | |
$maxRedirects = 5 | |
$method = "GET" | |
$noProxy = false | |
$parsedUrl | |
$postData = null | |
string | $profileName |
Profiler | $profiler |
$proxy = null | |
$reqHeaders = [] | |
$respHeaders = [] | |
$respStatus = "200 Ok" | |
$respVersion = "0.9" | |
$sslVerifyCert = true | |
$sslVerifyHost = true | |
$timeout = 'default' | |
$url | |
LoggerInterface | |
Static Private Member Functions | |
static | isLocalURL ($url) |
Check if the URL can be served by localhost. More... | |
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 33 of file MWHttpRequest.php.
|
protected |
string | $url | Url to use. If protocol-relative, will be expanded to an http:// URL |
array | $options | (optional) extra params to pass (see Http::request()) |
string | $caller | The method making this request, for profiling |
Profiler | $profiler | An instance of the profiler for profiling, or null |
Definition at line 86 of file MWHttpRequest.php.
References $options, $profiler, $url, as, global, Http\isValidURI(), StatusValue\newFatal(), StatusValue\newGood(), PROTO_HTTP, setUserAgent(), wfExpandUrl(), and wfParseUrl().
MWHttpRequest::canFollowRedirects | ( | ) |
Returns true if the backend can follow redirects.
Overridden by the child classes.
Definition at line 615 of file MWHttpRequest.php.
|
static |
Simple function to test if we can make any sort of requests at all, using cURL or fopen()
Definition at line 155 of file MWHttpRequest.php.
References wfIniGetBool().
Referenced by Installer\subscribeToMediaWikiAnnounce().
MWHttpRequest::execute | ( | ) |
Take care of whatever is necessary to perform the URI request.
Definition at line 364 of file MWHttpRequest.php.
References content, proxySetup(), setCallback(), setUserAgent(), and Http\userAgent().
|
static |
Generate a new request object.
string | $url | Url to use |
array | $options | (optional) extra params to pass (see Http::request()) |
string | $caller | The method making this request, for profiling |
MWException |
Definition at line 168 of file MWHttpRequest.php.
References Http\$httpEngine, $options, $url, Profiler\instance(), and wfIniGetBool().
Referenced by Parser\fetchScaryTemplateMaybeFromCache(), ThumbnailRenderJob\hitThumbUrl(), ForeignAPIRepo\httpGet(), SpecialUploadStash\outputRemoteScaledThumb(), UploadFromUrl\reallyFetchFile(), Http\request(), Installer\subscribeToMediaWikiAnnounce(), ApiLoginTest\testApiLoginGotCookie(), and MediaWiki\Tidy\Html5Depurate\tidy().
MWHttpRequest::getContent | ( | ) |
Get the body, or content, of the response to the request.
Definition at line 206 of file MWHttpRequest.php.
References $content.
MWHttpRequest::getCookieJar | ( | ) |
Returns the cookie jar in use.
Definition at line 512 of file MWHttpRequest.php.
References $cookieJar, and parseHeader().
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).
Definition at line 571 of file MWHttpRequest.php.
References $url, and getResponseHeaders().
Referenced by parseCookies().
MWHttpRequest::getHeaderList | ( | ) |
Get an array of the headers.
Definition at line 303 of file MWHttpRequest.php.
References $name, $value, and as.
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().
MWHttpRequest::getResponseHeader | ( | $header | ) |
Returns the value of the given response header.
string | $header |
Definition at line 485 of file MWHttpRequest.php.
References $header, and parseHeader().
Referenced by PhpHttpRequest\execute().
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.
Definition at line 471 of file MWHttpRequest.php.
References $respHeaders, and parseHeader().
Referenced by getFinalUrl().
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.)
Definition at line 436 of file MWHttpRequest.php.
References $respStatus, and parseHeader().
|
staticprivate |
Check if the URL can be served by localhost.
string | $url | Full url to check |
Definition at line 246 of file MWHttpRequest.php.
References $matches, $url, $wgCommandLineMode, and global.
MWHttpRequest::isRedirect | ( | ) |
Returns true if the last status code was a redirect.
Definition at line 449 of file MWHttpRequest.php.
References $status, and parseHeader().
Referenced by PhpHttpRequest\execute().
|
protected |
Parse the cookies in the response headers and store them in the cookie jar.
Definition at line 540 of file MWHttpRequest.php.
References $url, as, and getFinalUrl().
Referenced by 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 389 of file MWHttpRequest.php.
References $header, $last, as, and parseCookies().
Referenced by CurlHttpRequest\execute(), PhpHttpRequest\execute(), getCookieJar(), getResponseHeader(), getResponseHeaders(), getStatus(), isRedirect(), and setStatus().
MWHttpRequest::proxySetup | ( | ) |
Take care of setting up the proxy (do nothing if "noProxy" is set)
Definition at line 225 of file MWHttpRequest.php.
References Http\getProxy().
Referenced by execute().
MWHttpRequest::read | ( | $fh, | |
$content | |||
) |
A generic callback to read the body of the response from a remote server.
resource | $fh | |
string | $content |
Definition at line 354 of file MWHttpRequest.php.
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.
callable | $callback |
MWException |
Definition at line 339 of file MWHttpRequest.php.
References $callback.
Referenced by execute().
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.
string | $name | |
mixed | $value | |
array | $attr |
Definition at line 529 of file MWHttpRequest.php.
References $name, $value, and CookieJar\setCookie().
MWHttpRequest::setCookieJar | ( | $jar | ) |
Tells the MWHttpRequest object to use this pre-loaded CookieJar.
CookieJar | $jar |
Definition at line 503 of file MWHttpRequest.php.
MWHttpRequest::setData | ( | $args | ) |
Set the parameters of the request.
array | $args |
Definition at line 216 of file MWHttpRequest.php.
References $args.
MWHttpRequest::setHeader | ( | $name, | |
$value | |||
) |
Set an arbitrary header.
string | $name | |
string | $value |
Definition at line 294 of file MWHttpRequest.php.
Referenced by setUserAgent().
MWHttpRequest::setLogger | ( | LoggerInterface | $logger | ) |
LoggerInterface | $logger |
Definition at line 146 of file MWHttpRequest.php.
References $logger.
|
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 418 of file MWHttpRequest.php.
References $code, list, and parseHeader().
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().
MWHttpRequest::setUserAgent | ( | $UA | ) |
Set the user agent.
string | $UA |
Definition at line 285 of file MWHttpRequest.php.
References setHeader().
Referenced by __construct(), and execute().
|
protected |
Definition at line 44 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\getCertOptions().
|
protected |
Definition at line 49 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), and setCallback().
|
protected |
Definition at line 36 of file MWHttpRequest.php.
Referenced by getContent(), read(), and CurlHttpRequest\readHeader().
|
protected |
Definition at line 56 of file MWHttpRequest.php.
Referenced by getCookieJar().
|
protected |
Definition at line 51 of file MWHttpRequest.php.
|
protected |
Definition at line 58 of file MWHttpRequest.php.
|
protected |
Definition at line 38 of file MWHttpRequest.php.
MWHttpRequest::$logger |
Definition at line 78 of file MWHttpRequest.php.
Referenced by setLogger().
|
protected |
Definition at line 50 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute().
|
protected |
Definition at line 45 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().
|
protected |
Definition at line 41 of file MWHttpRequest.php.
|
protected |
Definition at line 48 of file MWHttpRequest.php.
Referenced by PhpHttpRequest\urlToTcp().
|
protected |
Definition at line 39 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().
|
protected |
Definition at line 73 of file MWHttpRequest.php.
|
protected |
Definition at line 68 of file MWHttpRequest.php.
Referenced by __construct().
|
protected |
Definition at line 40 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute().
|
protected |
Definition at line 46 of file MWHttpRequest.php.
|
protected |
Definition at line 61 of file MWHttpRequest.php.
Referenced by getResponseHeaders().
|
protected |
Definition at line 60 of file MWHttpRequest.php.
Referenced by getStatus().
|
protected |
Definition at line 59 of file MWHttpRequest.php.
|
protected |
Definition at line 43 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().
|
protected |
Definition at line 42 of file MWHttpRequest.php.
MWHttpRequest::$status |
Definition at line 63 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), PhpHttpRequest\execute(), and isRedirect().
|
protected |
Definition at line 37 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().
|
protected |
Definition at line 47 of file MWHttpRequest.php.
Referenced by __construct(), PhpHttpRequest\execute(), factory(), MWHttpRequestTester\factory(), getFinalUrl(), isLocalURL(), parseCookies(), and PhpHttpRequest\urlToTcp().
|
protected |
Definition at line 78 of file MWHttpRequest.php.
const MWHttpRequest::SUPPORTS_FILE_POSTS = false |
Definition at line 34 of file MWHttpRequest.php.