Changeset View
Changeset View
Standalone View
Standalone View
src/conduit/ConduitClient.php
| <?php | <?php | ||||
| final class ConduitClient extends Phobject { | final class ConduitClient extends Phobject { | ||||
| private $uri; | private $uri; | ||||
| private $host; | private $host; | ||||
| private $connectionID; | private $connectionID; | ||||
| private $sessionKey; | private $sessionKey; | ||||
| private $timeout = 300.0; | private $timeout = 300.0; | ||||
| private $username; | private $username; | ||||
| private $password; | private $password; | ||||
| private $publicKey; | private $publicKey; | ||||
| private $privateKey; | private $privateKey; | ||||
| private $conduitToken; | private $conduitToken; | ||||
| private $oauthToken; | private $oauthToken; | ||||
| private $capabilities = array(); | |||||
| const AUTH_ASYMMETRIC = 'asymmetric'; | const AUTH_ASYMMETRIC = 'asymmetric'; | ||||
| const SIGNATURE_CONSIGN_1 = 'Consign1.0/'; | const SIGNATURE_CONSIGN_1 = 'Consign1.0/'; | ||||
| public function getConnectionID() { | public function getConnectionID() { | ||||
| return $this->connectionID; | return $this->connectionID; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public function setSigningKeys( | ||||
| $public_key, | $public_key, | ||||
| PhutilOpaqueEnvelope $private_key) { | PhutilOpaqueEnvelope $private_key) { | ||||
| $this->publicKey = $public_key; | $this->publicKey = $public_key; | ||||
| $this->privateKey = $private_key; | $this->privateKey = $private_key; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function enableCapabilities(array $capabilities) { | |||||
| $this->capabilities += array_fuse($capabilities); | |||||
| return $this; | |||||
| } | |||||
| public function callMethod($method, array $params) { | public function callMethod($method, array $params) { | ||||
| $meta = array(); | $meta = array(); | ||||
| if ($this->sessionKey) { | if ($this->sessionKey) { | ||||
| $meta['sessionKey'] = $this->sessionKey; | $meta['sessionKey'] = $this->sessionKey; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | $data = array( | ||||
| // This is a hint to Phabricator that the client expects a Conduit | // This is a hint to Phabricator that the client expects a Conduit | ||||
| // response. It is not necessary, but provides better error messages in | // response. It is not necessary, but provides better error messages in | ||||
| // some cases. | // some cases. | ||||
| '__conduit__' => true, | '__conduit__' => true, | ||||
| ); | ); | ||||
| // Always use the cURL-based HTTPSFuture, for proxy support and other | // Always use the cURL-based HTTPSFuture, for proxy support and other | ||||
| // protocol edge cases that HTTPFuture does not support. | // protocol edge cases that HTTPFuture does not support. | ||||
| $core_future = new HTTPSFuture($uri, $data); | $core_future = new HTTPSFuture($uri); | ||||
| $core_future->addHeader('Host', $this->getHostStringForHeader()); | $core_future->addHeader('Host', $this->getHostStringForHeader()); | ||||
| $core_future->setMethod('POST'); | $core_future->setMethod('POST'); | ||||
| $core_future->setTimeout($this->timeout); | $core_future->setTimeout($this->timeout); | ||||
| // See T13507. If possible, try to compress requests. To compress requests, | |||||
| // we must have "gzencode()" available and the server needs to have | |||||
| // asserted it has the "gzip" capability. | |||||
| $can_gzip = | |||||
| (function_exists('gzencode')) && | |||||
| (isset($this->capabilities['gzip'])); | |||||
| if ($can_gzip) { | |||||
| $gzip_data = phutil_build_http_querystring($data); | |||||
| $gzip_data = gzencode($gzip_data); | |||||
| $core_future->addHeader('Content-Encoding', 'gzip'); | |||||
| $core_future->setData($gzip_data); | |||||
| } else { | |||||
| $core_future->setData($data); | |||||
| } | |||||
| if ($this->username !== null) { | if ($this->username !== null) { | ||||
| $core_future->setHTTPBasicAuthCredentials( | $core_future->setHTTPBasicAuthCredentials( | ||||
| $this->username, | $this->username, | ||||
| $this->password); | $this->password); | ||||
| } | } | ||||
| return id(new ConduitFuture($core_future)) | return id(new ConduitFuture($core_future)) | ||||
| ->setClient($this, $method); | ->setClient($this, $method); | ||||
| ▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines | |||||