Ejemplo n.º 1
0
 /**
  * Perform request using Microsoft_Http_Transport channel
  *
  * @param string $path Path
  * @param string $queryString Query string
  * @param string $httpVerb HTTP verb the request will use
  * @param array $headers x-ms headers to add
  * @param boolean $forTableStorage Is the request for table storage?
  * @param mixed $rawData Optional RAW HTTP data to be sent over the wire
  * @param string $resourceType Resource type
  * @param string $requiredPermission Required permission
  * @return Microsoft_Http_Response
  */
 protected function performRequest($path = '/', $queryString = '', $httpVerb = Microsoft_Http_Transport::VERB_GET, $headers = array(), $forTableStorage = false, $rawData = null, $resourceType = Microsoft_WindowsAzure_Storage::RESOURCE_UNKNOWN, $requiredPermission = Microsoft_WindowsAzure_Credentials::PERMISSION_READ)
 {
     // Clean path
     if (strpos($path, '/') !== 0) {
         $path = '/' . $path;
     }
     // Clean headers
     if (is_null($headers)) {
         $headers = array();
     }
     // Add version header
     $headers['x-ms-version'] = $this->_apiVersion;
     // URL encoding
     $path = self::urlencode($path);
     $queryString = self::urlencode($queryString);
     // Generate URL and sign request
     $requestUrl = $this->_credentials->signRequestUrl($this->getBaseUrl() . $path . $queryString, $resourceType, $requiredPermission);
     $requestHeaders = $this->_credentials->signRequestHeaders($httpVerb, $path, $queryString, $headers, $forTableStorage, $resourceType, $requiredPermission);
     $requestClient = Microsoft_Http_Transport::createChannel();
     if ($this->_useProxy) {
         $requestClient->setProxy($this->_useProxy, $this->_proxyUrl, $this->_proxyPort, $this->_proxyCredentials);
     }
     $response = $this->_retryPolicy->execute(array($requestClient, 'request'), array($httpVerb, $requestUrl, array(), $requestHeaders, $rawData));
     $requestClient = null;
     unset($requestClient);
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Perform batch using Microsoft_Http_Transport channel, combining all batch operations into one request
  *
  * @param array $operations Operations in batch
  * @param boolean $forTableStorage Is the request for table storage?
  * @param boolean $isSingleSelect Is the request a single select statement?
  * @param string $resourceType Resource type
  * @param string $requiredPermission Required permission
  * @return Microsoft_Http_Response
  */
 public function performBatch($operations = array(), $forTableStorage = false, $isSingleSelect = false, $resourceType = Microsoft_WindowsAzure_Storage::RESOURCE_UNKNOWN, $requiredPermission = Microsoft_WindowsAzure_Credentials::PERMISSION_READ)
 {
     // Generate boundaries
     $batchBoundary = 'batch_' . md5(time() . microtime());
     $changesetBoundary = 'changeset_' . md5(time() . microtime());
     // Set headers
     $headers = array();
     // Add version header
     $headers['x-ms-version'] = $this->_apiVersion;
     // Add content-type header
     $headers['Content-Type'] = 'multipart/mixed; boundary=' . $batchBoundary;
     // Set path and query string
     $path = '/$batch';
     $queryString = '';
     // Set verb
     $httpVerb = Microsoft_Http_Transport::VERB_POST;
     // Generate raw data
     $rawData = '';
     // Single select?
     if ($isSingleSelect) {
         $operation = $operations[0];
         $rawData .= '--' . $batchBoundary . "\n";
         $rawData .= 'Content-Type: application/http' . "\n";
         $rawData .= 'Content-Transfer-Encoding: binary' . "\n\n";
         $rawData .= $operation;
         $rawData .= '--' . $batchBoundary . '--';
     } else {
         $rawData .= '--' . $batchBoundary . "\n";
         $rawData .= 'Content-Type: multipart/mixed; boundary=' . $changesetBoundary . "\n\n";
         // Add operations
         foreach ($operations as $operation) {
             $rawData .= '--' . $changesetBoundary . "\n";
             $rawData .= 'Content-Type: application/http' . "\n";
             $rawData .= 'Content-Transfer-Encoding: binary' . "\n\n";
             $rawData .= $operation;
         }
         $rawData .= '--' . $changesetBoundary . '--' . "\n";
         $rawData .= '--' . $batchBoundary . '--';
     }
     // Generate URL and sign request
     $requestUrl = $this->_credentials->signRequestUrl($this->getBaseUrl() . $path . $queryString, $resourceType, $requiredPermission);
     $requestHeaders = $this->_credentials->signRequestHeaders($httpVerb, $path, $queryString, $headers, $forTableStorage, $resourceType, $requiredPermission);
     $requestClient = Microsoft_Http_Transport::createChannel();
     if ($this->_useProxy) {
         $requestClient->setProxy($this->_useProxy, $this->_proxyUrl, $this->_proxyPort, $this->_proxyCredentials);
     }
     $response = $this->_retryPolicy->execute(array($requestClient, 'request'), array($httpVerb, $requestUrl, array(), $requestHeaders, $rawData));
     $requestClient = null;
     unset($requestClient);
     return $response;
 }