import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
@ -15,16 +14,11 @@
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @subpackage Gdata
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* Zend_Http_Client
|
||||
*/
|
||||
@ -38,7 +32,8 @@ require_once 'Zend/Http/Client.php';
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @subpackage Gdata
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
@ -49,12 +44,12 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
* This key is used for AuthSub authentication. If this value is set,
|
||||
* it is assuemd that secure AuthSub is desired.
|
||||
*
|
||||
* @var resource
|
||||
* @var resource
|
||||
*/
|
||||
private $_authSubPrivateKeyId = null;
|
||||
|
||||
/**
|
||||
* Token for AuthSub authentication.
|
||||
* Token for AuthSub authentication.
|
||||
* If this token is set, AuthSub authentication is used.
|
||||
*
|
||||
* @var string
|
||||
@ -62,7 +57,7 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
private $_authSubToken = null;
|
||||
|
||||
/**
|
||||
* Token for ClientLogin authentication.
|
||||
* Token for ClientLogin authentication.
|
||||
* If only this token is set, ClientLogin authentication is used.
|
||||
*
|
||||
* @var string
|
||||
@ -78,6 +73,14 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
*/
|
||||
private $_clientLoginKey = null;
|
||||
|
||||
/**
|
||||
* True if this request is being made with data supplied by
|
||||
* a stream object instead of a raw encoded string.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_streamingRequest = null;
|
||||
|
||||
/**
|
||||
* Sets the PEM formatted private key, as read from a file.
|
||||
*
|
||||
@ -86,11 +89,11 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
*
|
||||
* @param string $file The location of the file containing the PEM key
|
||||
* @param string $passphrase The optional private key passphrase
|
||||
* @param bool $useIncludePath Whether to search the include_path
|
||||
* @param bool $useIncludePath Whether to search the include_path
|
||||
* for the file
|
||||
* @return void
|
||||
*/
|
||||
public function setAuthSubPrivateKeyFile($file, $passphrase = null,
|
||||
public function setAuthSubPrivateKeyFile($file, $passphrase = null,
|
||||
$useIncludePath = false) {
|
||||
$fp = fopen($file, "r", $useIncludePath);
|
||||
$key = '';
|
||||
@ -133,7 +136,7 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
public function getAuthSubPrivateKeyId() {
|
||||
return $this->_authSubPrivateKeyId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the AuthSub token used for authentication
|
||||
*
|
||||
@ -146,7 +149,7 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
/**
|
||||
* Sets the AuthSub token used for authentication
|
||||
*
|
||||
* @param string $token The token
|
||||
* @param string $token The token
|
||||
* @return Zend_Gdata_HttpClient Provides a fluent interface
|
||||
*/
|
||||
public function setAuthSubToken($token) {
|
||||
@ -157,7 +160,7 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
/**
|
||||
* Gets the ClientLogin token used for authentication
|
||||
*
|
||||
* @return string The token
|
||||
* @return string The token
|
||||
*/
|
||||
public function getClientLoginToken() {
|
||||
return $this->_clientLoginToken;
|
||||
@ -166,7 +169,7 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
/**
|
||||
* Sets the ClientLogin token used for authentication
|
||||
*
|
||||
* @param string $token The token
|
||||
* @param string $token The token
|
||||
* @return Zend_Gdata_HttpClient Provides a fluent interface
|
||||
*/
|
||||
public function setClientLoginToken($token) {
|
||||
@ -187,12 +190,12 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
*
|
||||
* @param string $method The HTTP method
|
||||
* @param string $url The URL
|
||||
* @param array $headers An associate array of headers to be
|
||||
* @param array $headers An associate array of headers to be
|
||||
* sent with the request or null
|
||||
* @param string $body The body of the request or null
|
||||
* @param string $contentType The MIME content type of the body or null
|
||||
* @throws Zend_Gdata_App_Exception if there was a signing failure
|
||||
* @return array The processed values in an associative array,
|
||||
* @return array The processed values in an associative array,
|
||||
* using the same names as the params
|
||||
*/
|
||||
public function filterHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null) {
|
||||
@ -206,7 +209,7 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
|
||||
// compute signature
|
||||
$pKeyId = $this->getAuthSubPrivateKeyId();
|
||||
$signSuccess = openssl_sign($dataToSign, $signature, $pKeyId,
|
||||
$signSuccess = openssl_sign($dataToSign, $signature, $pKeyId,
|
||||
OPENSSL_ALGO_SHA1);
|
||||
if (!$signSuccess) {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
@ -242,4 +245,102 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current connection adapter
|
||||
*
|
||||
* @return Zend_Http_Client_Adapter_Interface|string $adapter
|
||||
*/
|
||||
public function getAdapter()
|
||||
{
|
||||
return $this->adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the connection adapter
|
||||
*
|
||||
* @param Zend_Http_Client_Adapter_Interface $adapter
|
||||
* @return void
|
||||
*/
|
||||
public function setAdapter($adapter)
|
||||
{
|
||||
if ($adapter == null) {
|
||||
$this->adapter = $adapter;
|
||||
} else {
|
||||
parent::setAdapter($adapter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the streamingRequest variable which controls whether we are
|
||||
* sending the raw (already encoded) POST data from a stream source.
|
||||
*
|
||||
* @param boolean $value The value to set.
|
||||
* @return void
|
||||
*/
|
||||
public function setStreamingRequest($value)
|
||||
{
|
||||
$this->_streamingRequest = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the client is set to perform streaming requests.
|
||||
*
|
||||
* @return boolean True if yes, false otherwise.
|
||||
*/
|
||||
public function getStreamingRequest()
|
||||
{
|
||||
if ($this->_streamingRequest()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the request body (for POST and PUT requests)
|
||||
*
|
||||
* @return string
|
||||
* @throws Zend_Http_Client_Exception
|
||||
*/
|
||||
protected function _prepareBody()
|
||||
{
|
||||
if($this->_streamingRequest) {
|
||||
$this->setHeaders(self::CONTENT_LENGTH,
|
||||
$this->raw_post_data->getTotalSize());
|
||||
return $this->raw_post_data;
|
||||
}
|
||||
else {
|
||||
return parent::_prepareBody();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all custom parameters we set.
|
||||
*
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function resetParameters()
|
||||
{
|
||||
$this->_streamingRequest = false;
|
||||
|
||||
return parent::resetParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw (already encoded) POST data from a stream source.
|
||||
*
|
||||
* This is used to support POSTing from open file handles without
|
||||
* caching the entire body into memory. It is a wrapper around
|
||||
* Zend_Http_Client::setRawData().
|
||||
*
|
||||
* @param string $data The request data
|
||||
* @param string $enctype The encoding type
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function setRawDataStream($data, $enctype = null)
|
||||
{
|
||||
$this->_streamingRequest = true;
|
||||
return $this->setRawData($data, $enctype);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user