Changeset View
Changeset View
Standalone View
Standalone View
src/future/http/HTTPFuture.php
| Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | public function isReady() { | ||||
| } | } | ||||
| if (!$this->socket) { | if (!$this->socket) { | ||||
| $this->stateStartTime = microtime(true); | $this->stateStartTime = microtime(true); | ||||
| $this->socket = $this->buildSocket(); | $this->socket = $this->buildSocket(); | ||||
| if (!$this->socket) { | if (!$this->socket) { | ||||
| return $this->stateReady; | return $this->stateReady; | ||||
| } | } | ||||
| $profiler = PhutilServiceProfiler::getInstance(); | |||||
| $this->profilerCallID = $profiler->beginServiceCall( | |||||
| array( | |||||
| 'type' => 'http', | |||||
| 'uri' => $this->getURI(), | |||||
| )); | |||||
| } | } | ||||
| if (!$this->stateConnected) { | if (!$this->stateConnected) { | ||||
| $read = array(); | $read = array(); | ||||
| $write = array($this->socket); | $write = array($this->socket); | ||||
| $except = array(); | $except = array(); | ||||
| $select = stream_select($read, $write, $except, $tv_sec = 0); | $select = stream_select($read, $write, $except, $tv_sec = 0); | ||||
| if ($write) { | if ($write) { | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | private function checkSocket() { | ||||
| } else if (!$this->stateWriteComplete) { | } else if (!$this->stateWriteComplete) { | ||||
| $this->setResult( | $this->setResult( | ||||
| $this->buildErrorResult( | $this->buildErrorResult( | ||||
| HTTPFutureTransportResponseStatus::ERROR_CONNECTION_FAILED)); | HTTPFutureTransportResponseStatus::ERROR_CONNECTION_FAILED)); | ||||
| } else { | } else { | ||||
| $this->setResult($this->parseRawHTTPResponse($this->response)); | $this->setResult($this->parseRawHTTPResponse($this->response)); | ||||
| } | } | ||||
| $profiler = PhutilServiceProfiler::getInstance(); | |||||
| $profiler->endServiceCall($this->profilerCallID, array()); | |||||
| return true; | return true; | ||||
| } | } | ||||
| private function buildErrorResult($error) { | private function buildErrorResult($error) { | ||||
| return array( | return array( | ||||
| $status = new HTTPFutureTransportResponseStatus($error, $this->getURI()), | $status = new HTTPFutureTransportResponseStatus($error, $this->getURI()), | ||||
| $body = null, | $body = null, | ||||
| $headers = array(), | $headers = array(), | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | private function buildHTTPRequest() { | ||||
| return | return | ||||
| "{$method} {$uri} HTTP/1.0\r\n". | "{$method} {$uri} HTTP/1.0\r\n". | ||||
| implode('', $headers). | implode('', $headers). | ||||
| "\r\n". | "\r\n". | ||||
| $data; | $data; | ||||
| } | } | ||||
| protected function getServiceProfilerStartParameters() { | |||||
| return array( | |||||
| 'type' => 'http', | |||||
| 'uri' => phutil_string_cast($this->getURI()), | |||||
| ); | |||||
| } | |||||
| } | } | ||||