/**
  * @covers WindowsAzure\Common\Internal\Http\HttpClient::setHeaders
  */
 public function testSetHeaders()
 {
     // Setup
     $channel = new HttpClient();
     $header1 = TestResources::HEADER1;
     $header2 = TestResources::HEADER2;
     $value1 = TestResources::HEADER1_VALUE;
     $value2 = TestResources::HEADER2_VALUE;
     $headers = array($header1 => $value1, $header2 => $value2);
     // Test
     $channel->setHeaders($headers);
     // Assert
     $channelHeaders = $channel->getHeaders();
     $this->assertCount(2, $channelHeaders);
     $this->assertEquals($value1, $channelHeaders[$header1]);
     $this->assertEquals($value2, $channelHeaders[$header2]);
 }
 private function _commitBlocks($url, $blockIds)
 {
     $baseUrl = new Url($url);
     $baseUrl->setQueryVariable(Resources::QP_COMP, 'blocklist');
     $xml = new \XMLWriter();
     $xml->openMemory();
     $xml->setIndent(true);
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('BlockList');
     foreach ($blockIds as $blockId) {
         $xml->writeElement('Latest', $blockId);
     }
     $xml->endElement();
     $xml->endDocument();
     $xmlContent = $xml->outputMemory();
     $method = Resources::HTTP_PUT;
     $filters = array();
     $statusCode = Resources::STATUS_CREATED;
     $headers = array(Resources::CONTENT_TYPE => Resources::BINARY_FILE_TYPE, Resources::X_MS_VERSION => Resources::STORAGE_API_LATEST_VERSION);
     $httpClient = new HttpClient();
     $httpClient->setMethod($method);
     $httpClient->setHeaders($headers);
     $httpClient->setExpectedStatusCode($statusCode);
     $httpClient->setBody($xmlContent);
     $httpClient->send($filters, $baseUrl);
 }
Esempio n. 3
0
 /**
  * Upload asset file to storage.
  *
  * @param WindowsAzure\MediaServices\Models\Locator $locator Write locator for
  * file upload
  *
  * @param string                                    $name    Uploading filename
  * @param string                                    $body    Uploading content
  *
  * @return none
  */
 public function uploadAssetFile($locator, $name, $body)
 {
     Validate::isA($locator, 'WindowsAzure\\Mediaservices\\Models\\Locator', 'locator');
     Validate::isString($name, 'name');
     Validate::notNull($body, 'body');
     $method = Resources::HTTP_PUT;
     $urlFile = $locator->getBaseUri() . '/' . $name;
     $url = new Url($urlFile . $locator->getContentAccessComponent());
     $filters = array();
     $statusCode = Resources::STATUS_CREATED;
     $headers = array(Resources::CONTENT_TYPE => Resources::BINARY_FILE_TYPE, Resources::X_MS_VERSION => Resources::STORAGE_API_LATEST_VERSION, Resources::X_MS_BLOB_TYPE => BlobType::BLOCK_BLOB);
     $httpClient = new HttpClient();
     $httpClient->setMethod($method);
     $httpClient->setHeaders($headers);
     $httpClient->setExpectedStatusCode($statusCode);
     $httpClient->setBody($body);
     $httpClient->send($filters, $url);
 }