in src/conduit/ConduitClient.php [96:188]
public function callMethod($method, array $params) {
$meta = array();
if ($this->sessionKey) {
$meta['sessionKey'] = $this->sessionKey;
}
if ($this->connectionID) {
$meta['connectionID'] = $this->connectionID;
}
if ($method == 'conduit.connect') {
$certificate = idx($params, 'certificate');
if ($certificate) {
$token = time();
$params['authToken'] = $token;
$params['authSignature'] = sha1($token.$certificate);
}
unset($params['certificate']);
}
if ($this->privateKey && $this->publicKey) {
$meta['auth.type'] = self::AUTH_ASYMMETRIC;
$meta['auth.key'] = $this->publicKey;
$meta['auth.host'] = $this->getHostStringForSignature();
$signature = $this->signRequest($method, $params, $meta);
$meta['auth.signature'] = $signature;
}
if ($this->conduitToken) {
$meta['token'] = $this->conduitToken;
}
if ($this->oauthToken) {
$meta['access_token'] = $this->oauthToken;
}
if ($meta) {
$params['__conduit__'] = $meta;
}
$uri = id(clone $this->uri)->setPath('/api/'.$method);
$data = array(
'params' => json_encode($params),
'output' => 'json',
// This is a hint to Phabricator that the client expects a Conduit
// response. It is not necessary, but provides better error messages in
// some cases.
'__conduit__' => true,
);
// Always use the cURL-based HTTPSFuture, for proxy support and other
// protocol edge cases that HTTPFuture does not support.
$core_future = new HTTPSFuture($uri);
$core_future->addHeader('Host', $this->getHostStringForHeader());
// UBER CODE
foreach ($this->extraHeaders as $header => $value) {
$core_future->addHeader($header, $value);
}
// UBER CODE END
$core_future->setMethod('POST');
$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) {
$core_future->setHTTPBasicAuthCredentials(
$this->username,
$this->password);
}
return id(new ConduitFuture($core_future))
->setClient($this, $method);
}