Changeset View
Changeset View
Standalone View
Standalone View
src/future/http/BaseHTTPFuture.php
Show All 20 Lines | |||||
abstract class BaseHTTPFuture extends Future { | abstract class BaseHTTPFuture extends Future { | ||||
private $method = 'GET'; | private $method = 'GET'; | ||||
private $timeout = 300.0; | private $timeout = 300.0; | ||||
private $headers = array(); | private $headers = array(); | ||||
private $uri; | private $uri; | ||||
private $data; | private $data; | ||||
private $expect; | private $expect; | ||||
private $disableContentDecoding; | |||||
/* -( Creating a New Request )--------------------------------------------- */ | /* -( Creating a New Request )--------------------------------------------- */ | ||||
/** | /** | ||||
* Build a new future which will make an HTTP request to a given URI, with | * 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 | * some optional data payload. Since this class is abstract you can't actually | ||||
* instantiate it; instead, build a new @{class:HTTPFuture} or | * instantiate it; instead, build a new @{class:HTTPFuture} or | ||||
▲ Show 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | public function getHTTPRequestByteLength() { | ||||
if (is_scalar($data)) { | if (is_scalar($data)) { | ||||
return strlen($data); | return strlen($data); | ||||
} | } | ||||
return strlen(phutil_build_http_querystring($data)); | return strlen(phutil_build_http_querystring($data)); | ||||
} | } | ||||
public function setDisableContentDecoding($disable_decoding) { | |||||
$this->disableContentDecoding = $disable_decoding; | |||||
return $this; | |||||
} | |||||
public function getDisableContentDecoding() { | |||||
return $this->disableContentDecoding; | |||||
} | |||||
/* -( Resolving the Request )---------------------------------------------- */ | /* -( Resolving the Request )---------------------------------------------- */ | ||||
/** | /** | ||||
* Exception-oriented @{method:resolve}. Throws if the status indicates an | * Exception-oriented @{method:resolve}. Throws if the status indicates an | ||||
* error occurred. | * error occurred. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | while (true) { | ||||
// then the normal response. Drop this chunk. | // then the normal response. Drop this chunk. | ||||
$response = $body; | $response = $body; | ||||
} else { | } else { | ||||
$headers = $this->parseHeaders(idx($matches, 'headers')); | $headers = $this->parseHeaders(idx($matches, 'headers')); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (!$this->getDisableContentDecoding()) { | |||||
$content_encoding = null; | $content_encoding = null; | ||||
foreach ($headers as $header) { | foreach ($headers as $header) { | ||||
list($name, $value) = $header; | list($name, $value) = $header; | ||||
$name = phutil_utf8_strtolower($name); | $name = phutil_utf8_strtolower($name); | ||||
if (!strcasecmp($name, 'Content-Encoding')) { | if (!strcasecmp($name, 'Content-Encoding')) { | ||||
$content_encoding = $value; | $content_encoding = $value; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
switch ($content_encoding) { | switch ($content_encoding) { | ||||
case 'gzip': | case 'gzip': | ||||
$decoded_body = gzdecode($body); | $decoded_body = @gzdecode($body); | ||||
if ($decoded_body === false) { | if ($decoded_body === false) { | ||||
return $this->buildMalformedResult($raw_response); | return $this->buildMalformedResult($raw_response); | ||||
} | } | ||||
$body = $decoded_body; | $body = $decoded_body; | ||||
break; | break; | ||||
} | } | ||||
} | |||||
$status = new HTTPFutureHTTPResponseStatus( | $status = new HTTPFutureHTTPResponseStatus( | ||||
$response_code, | $response_code, | ||||
$body, | $body, | ||||
$headers, | $headers, | ||||
$this->expect); | $this->expect); | ||||
return array($status, $body, $headers); | return array($status, $body, $headers); | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |