Changeset View
Changeset View
Standalone View
Standalone View
src/future/http/HTTPSFuture.php
| Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | $this->files[$key] = array( | ||||
| 'name' => $name, | 'name' => $name, | ||||
| 'mime' => $mime_type, | 'mime' => $mime_type, | ||||
| ); | ); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function isReady() { | public function isReady() { | ||||
| if (isset($this->result)) { | if ($this->hasResult()) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| $uri = $this->getURI(); | $uri = $this->getURI(); | ||||
| $domain = id(new PhutilURI($uri))->getDomain(); | $domain = id(new PhutilURI($uri))->getDomain(); | ||||
| $is_download = $this->isDownload(); | $is_download = $this->isDownload(); | ||||
| ▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | if ($err_code) { | ||||
| HTTPFutureCertificateResponseStatus::ERROR_IMMUTABLE_CERTIFICATES, | HTTPFutureCertificateResponseStatus::ERROR_IMMUTABLE_CERTIFICATES, | ||||
| $uri); | $uri); | ||||
| } else { | } else { | ||||
| $status = new HTTPFutureCURLResponseStatus($err_code, $uri); | $status = new HTTPFutureCURLResponseStatus($err_code, $uri); | ||||
| } | } | ||||
| $body = null; | $body = null; | ||||
| $headers = array(); | $headers = array(); | ||||
| $this->result = array($status, $body, $headers); | $this->setResult(array($status, $body, $headers)); | ||||
| } else if ($this->parser) { | } else if ($this->parser) { | ||||
| $streaming_parser = $this->parser; | $streaming_parser = $this->parser; | ||||
| try { | try { | ||||
| $responses = $streaming_parser->getResponses(); | $responses = $streaming_parser->getResponses(); | ||||
| $final_response = last($responses); | $final_response = last($responses); | ||||
| $result = array( | $result = array( | ||||
| $final_response->getStatus(), | $final_response->getStatus(), | ||||
| $final_response->getBody(), | $final_response->getBody(), | ||||
| $final_response->getHeaders(), | $final_response->getHeaders(), | ||||
| ); | ); | ||||
| } catch (HTTPFutureParseResponseStatus $ex) { | } catch (HTTPFutureParseResponseStatus $ex) { | ||||
| $result = array($ex, null, array()); | $result = array($ex, null, array()); | ||||
| } | } | ||||
| $this->result = $result; | $this->setResult($result); | ||||
| } else { | } else { | ||||
| // cURL returns headers of all redirects, we strip all but the final one. | // cURL returns headers of all redirects, we strip all but the final one. | ||||
| $redirects = curl_getinfo($curl, CURLINFO_REDIRECT_COUNT); | $redirects = curl_getinfo($curl, CURLINFO_REDIRECT_COUNT); | ||||
| $result = preg_replace('/^(.*\r\n\r\n){'.$redirects.'}/sU', '', $result); | $result = preg_replace('/^(.*\r\n\r\n){'.$redirects.'}/sU', '', $result); | ||||
| $this->result = $this->parseRawHTTPResponse($result); | $this->setResult($this->parseRawHTTPResponse($result)); | ||||
| } | } | ||||
| curl_multi_remove_handle(self::$multi, $curl); | curl_multi_remove_handle(self::$multi, $curl); | ||||
| unset(self::$results[(int)$curl]); | unset(self::$results[(int)$curl]); | ||||
| // NOTE: We want to use keepalive if possible. Return the handle to a | // NOTE: We want to use keepalive if possible. Return the handle to a | ||||
| // pool for the domain; don't close it. | // pool for the domain; don't close it. | ||||
| if ($this->shouldReuseHandles()) { | if ($this->shouldReuseHandles()) { | ||||
| self::$pool[$domain][] = $curl; | self::$pool[$domain][] = $curl; | ||||
| } | } | ||||
| if ($is_download) { | if ($is_download) { | ||||
| if ($this->downloadHandle) { | if ($this->downloadHandle) { | ||||
| fflush($this->downloadHandle); | fflush($this->downloadHandle); | ||||
| fclose($this->downloadHandle); | fclose($this->downloadHandle); | ||||
| $this->downloadHandle = null; | $this->downloadHandle = null; | ||||
| } | } | ||||
| } | } | ||||
| $sink = $this->getProgressSink(); | $sink = $this->getProgressSink(); | ||||
| if ($sink) { | if ($sink) { | ||||
| $status = head($this->result); | $status = head($this->getResult()); | ||||
| if ($status->isError()) { | if ($status->isError()) { | ||||
| $sink->didFailWork(); | $sink->didFailWork(); | ||||
| } else { | } else { | ||||
| $sink->didCompleteWork(); | $sink->didCompleteWork(); | ||||
| } | } | ||||
| } | } | ||||
| $profiler = PhutilServiceProfiler::getInstance(); | $profiler = PhutilServiceProfiler::getInstance(); | ||||
| ▲ Show 20 Lines • Show All 295 Lines • Show Last 20 Lines | |||||