Creating a New Request
- final public function __construct($uri, $data) — Build a new future which will make an HTTP request to a given URI, with some optional data payload. Since this class is abstract you can't actually instantiate it; instead, build a new @{class:HTTPFuture} or @{class:HTTPSFuture}.
Configuring the Request
- public function setTimeout($timeout) — Set a timeout for the service call. If the request hasn't resolved yet, the future will resolve with a status that indicates the request timed out. You can determine if a status is a timeout status by calling isTimeout() on the status object.
- public function getTimeout() — Get the currently configured timeout.
- final public function setMethod($method) — Select the HTTP method (e.g., "GET", "POST", "PUT") to use for the request. By default, requests use "GET".
- final public function getMethod() — Get the HTTP method the request will use.
- public function setURI($uri) — Set the URI to send the request to. Note that this is also a constructor parameter.
- public function getURI() — Get the fully-qualified URI the request will be made to.
- public function setData($data) — Provide data to send along with the request. Note that this is also a constructor parameter; it may be more convenient to provide it there. Data must be a string (in which case it will be sent raw) or an array (in which case it will be encoded and sent as 'application/x-www-form-urlencoded').
- public function getData() — Get the data which will be sent with the request.
- public function addHeader($name, $value) — Add an HTTP header to the request. The same header name can be specified more than once, which will cause multiple headers to be sent.
- public function getHeaders($filter) — Get headers which will be sent with the request. Optionally, you can provide a filter, which will return only headers with that name. For example:
- public function setExpectStatus($status_codes) — Set the status codes that are expected in the response. If set, isError on the status object will return true for status codes that are not in the input array. Otherwise, isError will be true for any HTTP status code outside the 2xx range (notwithstanding other errors such as connection or transport issues).
- public function setHTTPBasicAuthCredentials($username, $password) — Add a HTTP basic authentication header to the request.
Resolving the Request
Internals
- protected function parseRawHTTPResponse($raw_response) — Parse a raw HTTP response into a <status, body, headers> tuple.
- protected function parseHeaders($head_raw) — Parse an HTTP header block.
- protected function buildMalformedResult($raw_response) — Build a result tuple indicating a parse error resulting from a malformed HTTP response.
Other Methods
- public function __get($name)
- public function __set($name, $value)
- public function current()
- public function key()
- public function next()
- public function rewind()
- public function valid()
- private function throwOnAttemptedIteration()
- public function getPhobjectClassConstant($key, $byte_limit) — Read the value of a class constant.
- public function isReady()
- public function resolve() — Resolve a future and return its result, blocking until the result is ready if necessary.
- final public function updateFuture()
- private function startServiceProfiler()
- private function endServiceProfiler()
- protected function getServiceProfilerStartParameters()
- protected function getServiceProfilerResultParameters()
- public function getReadSockets() — Retrieve a list of sockets which we can wait to become readable while a future is resolving. If your future has sockets which can be `select()`ed, return them here (or in @{method:getWriteSockets}) to make the resolve loop do a `select()`. If you do not return sockets in either case, you'll get a busy wait.
- public function getWriteSockets() — Retrieve a list of sockets which we can wait to become writable while a future is resolving. See @{method:getReadSockets}.
- public function getDefaultWait() — Default amount of time to wait on stream select for this future. Normally 1 second is fine, but if the future has a timeout sooner than that it should return the amount of time left before the timeout.
- public function start()
- final protected function getResult() — Retrieve the final result of the future.
- final protected function setResult($result)
- final public function hasResult()
- private function setException($exception)
- private function getException()
- final public function hasException()
- final public function setFutureKey($key)
- final public function getFutureKey()
- final public function setRaiseExceptionOnStart($raise)
- final public function getHasFutureStarted()
- final public function canResolve()
- private function endFuture()
- public function getExpectStatus() — Return list of expected status codes, or null if not set.
- public function getHTTPRequestByteLength()
- public function setDisableContentDecoding($disable_decoding)
- public function getDisableContentDecoding()
- public function setCABundleFromString($certificate) — Create a temp file containing an SSL cert, and use it for this session.
- public function setCABundleFromPath($path) — Set the SSL certificate to use for this session, given a path.
- public function getCABundle() — Get the path to the SSL certificate for this session.
- public function setFollowLocation($follow) — Set whether Location headers in the response will be respected. The default is true.
- public function getFollowLocation() — Get whether Location headers in the response will be respected.
- public static function setGlobalCABundleFromPath($path) — Set the fallback CA certificate if one is not specified for the session, given a path.
- public static function setGlobalCABundleFromString($certificate) — Set the fallback CA certificate if one is not specified for the session, given a string.
- public static function getGlobalCABundle() — Get the fallback global CA certificate
- public static function loadContent($uri, $timeout) — Load contents of remote URI. Behaves pretty much like `@file_get_contents($uri)` but doesn't require `allow_url_fopen`.
- public function setDownloadPath($download_path)
- public function setProgressSink($progress_sink)
- public function getProgressSink()
- public function addCURLOption($option_key, $option_value) — See T13533. This supports an install-specific Kerberos workflow.
- public function attachFileData($key, $data, $name, $mime_type) — Attach a file to the request.
- public function didReceiveDataCallback($handle, $data) — Callback invoked by cURL as it reads HTTP data from the response. We save the data to a buffer.
- public function read() — Read data from the response buffer.
- public function discardBuffers() — Discard any buffered data. Normally, you call this after reading the data with @{method:read}.
- private function formatRequestDataForCURL() — Produces a value safe to pass to `CURLOPT_POSTFIELDS`.
- private function checkForDangerousCURLMagic($string, $is_query_string) — Detect strings which will cause cURL to do horrible, insecure things.
- private function canSetCAInfo() — Determine whether CURLOPT_CAINFO is usable on this system.
- public function write($raw_body) — Write a raw HTTP body into the request.
- public function willWriteBody($handle, $infile, $len) — Callback to pass data to cURL.
- private function shouldReuseHandles()
- private function isDownload()
- private function canAcceptGzip()