MediaWiki REL1_37
|
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 | |
__construct ( $url, array $options=[], $caller=__METHOD__, Profiler $profiler=null) | |
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. | |
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. | |
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, array $attr=[]) | |
Sets a cookie. | |
setCookieJar (CookieJar $jar) | |
Tells the MWHttpRequest object to use this pre-loaded CookieJar. | |
setData (array $args) | |
Set the parameters of the request. | |
setHeader ( $name, $value) | |
Set an arbitrary header. | |
setLogger (LoggerInterface $logger) | |
setOriginalRequest ( $originalRequest) | |
Set information about the original request. | |
setUserAgent ( $UA) | |
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, array $options=null, $caller=__METHOD__) |
Generate a new request object. | |
static | isValidURI ( $uri) |
Check that the given URI is a valid one. | |
Public Attributes | |
const | SUPPORTS_FILE_POSTS = false |
Protected Member Functions | |
doSetCallback ( $callback) | |
Worker function for setting callbacks. | |
getHeaderList () | |
Get an array of the headers. | |
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. | |
prepare () | |
proxySetup () | |
Take care of setting up the proxy (do nothing if "noProxy" is set) | |
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). | |
Protected Attributes | |
$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 | |
Static Private Member Functions | |
static | isLocalURL ( $url) |
Check if the URL can be served by localhost. | |
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.
MWHttpRequest::__construct | ( | $url, | |
array | $options = [] , |
||
$caller = __METHOD__ , |
|||
Profiler | $profiler = null |
||
) |
string | $url | Url to use. If protocol-relative, will be expanded to an http:// URL |
array | $options | (optional) extra params to pass (see HttpRequestFactory::create()) @phpcs:ignore Generic.Files.LineLength |
string | $caller | The method making this request, for profiling |
Profiler | null | $profiler | An instance of the profiler for profiling, or null |
Exception |
Reimplemented in GuzzleHttpRequest.
Definition at line 98 of file MWHttpRequest.php.
References $url, $wgHTTPConnectTimeout, $wgHTTPTimeout, PROTO_HTTP, setHeader(), setOriginalRequest(), setUserAgent(), wfDeprecated(), wfExpandUrl(), and wfParseUrl().
MWHttpRequest::canFollowRedirects | ( | ) |
Returns true if the backend can follow redirects.
Overridden by the child classes.
Reimplemented in CurlHttpRequest.
Definition at line 643 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 180 of file MWHttpRequest.php.
References wfIniGetBool().
|
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.
callable | null | $callback |
InvalidArgumentException |
Reimplemented in GuzzleHttpRequest.
Definition at line 351 of file MWHttpRequest.php.
Referenced by prepare(), and setCallback().
MWHttpRequest::execute | ( | ) |
Take care of whatever is necessary to perform the URI request.
Reimplemented in CurlHttpRequest, GuzzleHttpRequest, and PhpHttpRequest.
Definition at line 381 of file MWHttpRequest.php.
|
static |
Generate a new request object.
string | $url | Url to use |
array | null | $options | (optional) extra params to pass (see HttpRequestFactory::create()) |
string | $caller | The method making this request, for profiling |
DomainException |
Definition at line 194 of file MWHttpRequest.php.
References $url.
MWHttpRequest::getContent | ( | ) |
Get the body, or content, of the response to the request.
Definition at line 207 of file MWHttpRequest.php.
References $content.
MWHttpRequest::getCookieJar | ( | ) |
Returns the cookie jar in use.
Definition at line 540 of file MWHttpRequest.php.
References parseHeader().
Referenced by GuzzleHttpRequest\execute().
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).
Definition at line 601 of file MWHttpRequest.php.
References $url, and getResponseHeaders().
Referenced by parseCookies().
|
protected |
Get an array of the headers.
Definition at line 304 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().
MWHttpRequest::getResponseHeader | ( | $header | ) |
Returns the value of the given response header.
string | $header | case-insensitive |
Definition at line 511 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. Header names are always in lowercase.
Definition at line 497 of file MWHttpRequest.php.
References 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 461 of file MWHttpRequest.php.
References parseHeader().
|
staticprivate |
Check if the URL can be served by localhost.
string | $url | Full url to check |
Definition at line 248 of file MWHttpRequest.php.
References $matches, $url, $wgCommandLineMode, and $wgLocalVirtualHosts.
MWHttpRequest::isRedirect | ( | ) |
Returns true if the last status code was a redirect.
Definition at line 474 of file MWHttpRequest.php.
References parseHeader().
Referenced by PhpHttpRequest\execute().
|
static |
Check that the given URI is a valid one.
This hardcodes a small set of protocols only, because we want to deterministically reject protocols not supported by all HTTP-transport methods.
"file://" specifically must not be allowed, for security reasons (see https://www.mediawiki.org/wiki/Special:Code/MediaWiki/r67684).
string | $uri | URI to check for validity |
Definition at line 693 of file MWHttpRequest.php.
|
protected |
Parse the cookies in the response headers and store them in the cookie jar.
Definition at line 572 of file MWHttpRequest.php.
References $url, and getFinalUrl().
Referenced by GuzzleHttpRequest\parseHeader(), and 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.
Reimplemented in GuzzleHttpRequest.
Definition at line 409 of file MWHttpRequest.php.
References $header, and parseCookies().
Referenced by CurlHttpRequest\execute(), PhpHttpRequest\execute(), getCookieJar(), getResponseHeader(), getResponseHeaders(), getStatus(), isRedirect(), and setStatus().
|
protected |
Reimplemented in GuzzleHttpRequest.
Definition at line 385 of file MWHttpRequest.php.
References doSetCallback(), proxySetup(), and setUserAgent().
Referenced by CurlHttpRequest\execute(), and PhpHttpRequest\execute().
|
protected |
Take care of setting up the proxy (do nothing if "noProxy" is set)
Definition at line 226 of file MWHttpRequest.php.
References $wgHTTPProxy.
Referenced by prepare().
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 370 of file MWHttpRequest.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.
callable | null | $callback |
InvalidArgumentException |
Reimplemented in GuzzleHttpRequest.
Definition at line 340 of file MWHttpRequest.php.
References doSetCallback().
MWHttpRequest::setCookie | ( | $name, | |
$value, | |||
array | $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.
string | $name | |
string | $value | |
array | $attr |
Definition at line 557 of file MWHttpRequest.php.
References CookieJar\setCookie().
MWHttpRequest::setCookieJar | ( | CookieJar | $jar | ) |
Tells the MWHttpRequest object to use this pre-loaded CookieJar.
To read response cookies from the jar, getCookieJar must be called first.
CookieJar | $jar |
Definition at line 531 of file MWHttpRequest.php.
MWHttpRequest::setData | ( | array | $args | ) |
Set the parameters of the request.
array | $args |
Definition at line 217 of file MWHttpRequest.php.
References $args.
MWHttpRequest::setHeader | ( | $name, | |
$value | |||
) |
Set an arbitrary header.
string | $name | |
string | $value |
Definition at line 295 of file MWHttpRequest.php.
Referenced by __construct(), and setUserAgent().
MWHttpRequest::setLogger | ( | LoggerInterface | $logger | ) |
LoggerInterface | $logger |
Definition at line 171 of file MWHttpRequest.php.
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.
WebRequest | array | $originalRequest | When in array form, it's expected to have the keys 'ip' and 'userAgent'. |
Definition at line 659 of file MWHttpRequest.php.
Referenced by __construct().
|
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 (1-299) or a redirect (300-399).
See RFC2616, section 10, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for a list of status codes.
Definition at line 440 of file MWHttpRequest.php.
References parseHeader().
Referenced by CurlHttpRequest\execute(), GuzzleHttpRequest\execute(), and PhpHttpRequest\execute().
MWHttpRequest::setUserAgent | ( | $UA | ) |
string | $UA |
Definition at line 286 of file MWHttpRequest.php.
References setHeader().
Referenced by __construct(), and prepare().
|
protected |
Definition at line 48 of file MWHttpRequest.php.
|
protected |
Definition at line 55 of file MWHttpRequest.php.
Referenced by GuzzleHttpRequest\doSetCallback(), and GuzzleHttpRequest\setCallback().
|
protected |
Definition at line 58 of file MWHttpRequest.php.
|
protected |
Definition at line 41 of file MWHttpRequest.php.
|
protected |
Definition at line 63 of file MWHttpRequest.php.
|
protected |
Definition at line 57 of file MWHttpRequest.php.
|
protected |
Definition at line 65 of file MWHttpRequest.php.
|
protected |
Definition at line 42 of file MWHttpRequest.php.
|
protected |
Definition at line 87 of file MWHttpRequest.php.
|
protected |
Definition at line 56 of file MWHttpRequest.php.
|
protected |
Definition at line 49 of file MWHttpRequest.php.
|
protected |
Definition at line 45 of file MWHttpRequest.php.
|
protected |
Definition at line 53 of file MWHttpRequest.php.
Referenced by PhpHttpRequest\urlToTcp().
|
protected |
Definition at line 43 of file MWHttpRequest.php.
Referenced by CurlHttpRequest\execute(), and GuzzleHttpRequest\execute().
|
protected |
Definition at line 82 of file MWHttpRequest.php.
|
protected |
Definition at line 77 of file MWHttpRequest.php.
Referenced by GuzzleHttpRequest\__construct().
|
protected |
Definition at line 44 of file MWHttpRequest.php.
|
protected |
Definition at line 51 of file MWHttpRequest.php.
|
protected |
Definition at line 69 of file MWHttpRequest.php.
|
protected |
Definition at line 67 of file MWHttpRequest.php.
|
protected |
Definition at line 66 of file MWHttpRequest.php.
|
protected |
Definition at line 47 of file MWHttpRequest.php.
|
protected |
Definition at line 46 of file MWHttpRequest.php.
|
protected |
Definition at line 72 of file MWHttpRequest.php.
|
protected |
Definition at line 39 of file MWHttpRequest.php.
|
protected |
Definition at line 52 of file MWHttpRequest.php.
Referenced by GuzzleHttpRequest\__construct(), __construct(), PhpHttpRequest\execute(), factory(), getFinalUrl(), isLocalURL(), parseCookies(), and PhpHttpRequest\urlToTcp().
const MWHttpRequest::SUPPORTS_FILE_POSTS = false |
Definition at line 34 of file MWHttpRequest.php.