[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/ -> HttpFunctions.php (summary)

Various HTTP related functions. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

File Size: 973 lines (26 kb)
Included or required:0 times
Referenced: 4 times
Includes or requires: 0 files

Defines 4 classes

Http:: (6 methods):
  request()
  get()
  post()
  isLocalURL()
  userAgent()
  isValidURI()

MWHttpRequest:: (24 methods):
  __construct()
  canMakeRequests()
  factory()
  getContent()
  setData()
  proxySetup()
  setUserAgent()
  setHeader()
  getHeaderList()
  setCallback()
  read()
  execute()
  parseHeader()
  setStatus()
  getStatus()
  isRedirect()
  getResponseHeaders()
  getResponseHeader()
  setCookieJar()
  getCookieJar()
  setCookie()
  parseCookies()
  getFinalUrl()
  canFollowRedirects()

CurlHttpRequest:: (3 methods):
  readHeader()
  execute()
  canFollowRedirects()

PhpHttpRequest:: (2 methods):
  urlToTcp()
  execute()


Class: Http  - X-Ref

Various HTTP related functions

request( $method, $url, $options = array()   X-Ref
Perform an HTTP request

param: string $method HTTP method. Usually GET/POST
param: string $url Full URL to act on. If protocol-relative, will be expanded to an http:// URL
param: array $options Options to pass to MWHttpRequest object.
return: string|bool (bool)false on failure or a string on success

get( $url, $timeout = 'default', $options = array()   X-Ref
Simple wrapper for Http::request( 'GET' )

param: string $url
param: string $timeout
param: array $options
return: string

post( $url, $options = array()   X-Ref
Simple wrapper for Http::request( 'POST' )

param: string $url
param: array $options
return: string

isLocalURL( $url )   X-Ref
Check if the URL can be served by localhost

param: string $url Full url to check
return: bool

userAgent()   X-Ref
A standard user-agent we can use for external requests.

return: string

isValidURI( $uri )   X-Ref
Checks that the given URI is a valid one. Hardcoding the
protocols, because we only want protocols that both cURL
and php support.

file:// should not be allowed here for security purpose (r67684)

param: string $uri URI to check for validity
return: bool

Class: MWHttpRequest  - X-Ref

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.
__construct( $url, $options = array()   X-Ref

param: string $url Url to use. If protocol-relative, will be expanded to an http:// URL
param: array $options (optional) extra params to pass (see Http::request())

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

return: bool

factory( $url, $options = null )   X-Ref
Generate a new request object

param: string $url Url to use
param: array $options (optional) extra params to pass (see Http::request())
return: CurlHttpRequest|PhpHttpRequest

getContent()   X-Ref
Get the body, or content, of the response to the request

return: string

setData( $args )   X-Ref
Set the parameters of the request

param: array $args

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

return: void

setUserAgent( $UA )   X-Ref
Set the user agent

param: string $UA

setHeader( $name, $value )   X-Ref
Set an arbitrary header

param: string $name
param: string $value

getHeaderList()   X-Ref
Get an array of the headers

return: array

setCallback( $callback )   X-Ref
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.

param: callable $callback

read( $fh, $content )   X-Ref
A generic callback to read the body of the response from a remote
server.

param: resource $fh
param: string $content
return: int

execute()   X-Ref
Take care of whatever is necessary to perform the URI request.

return: Status

parseHeader()   X-Ref
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.


setStatus()   X-Ref
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.)


getStatus()   X-Ref
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.)

return: int

isRedirect()   X-Ref
Returns true if the last status code was a redirect.

return: bool

getResponseHeaders()   X-Ref
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.

return: array

getResponseHeader( $header )   X-Ref
Returns the value of the given response header.

param: string $header
return: string

setCookieJar( $jar )   X-Ref
Tells the MWHttpRequest object to use this pre-loaded CookieJar.

param: CookieJar $jar

getCookieJar()   X-Ref
Returns the cookie jar in use.

return: CookieJar

setCookie( $name, $value = null, $attr = null )   X-Ref
Sets a cookie. Used before a request to set up any individual
cookies. Used internally after a request to parse the
Set-Cookie headers.

param: string $name
param: mixed $value
param: array $attr

parseCookies()   X-Ref
Parse the cookies in the response headers and store them in the cookie jar.


getFinalUrl()   X-Ref
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).

return: string

canFollowRedirects()   X-Ref
Returns true if the backend can follow redirects. Overridden by the
child classes.

return: bool

Class: CurlHttpRequest  - X-Ref

MWHttpRequest implemented using internal curl compiled into PHP

readHeader( $fh, $content )   X-Ref

param: resource $fh
param: string $content
return: int

execute()   X-Ref
No description

canFollowRedirects()   X-Ref

return: bool

Class: PhpHttpRequest  - X-Ref

urlToTcp( $url )   X-Ref

param: string $url
return: string

execute()   X-Ref
No description



Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1