public function testCreateHeaders()
 {
     $indexes = ['foo_bin' => ['bar', 'baz'], 'foo_int' => [42, 50]];
     $translator = new Api\Http\Translator\SecondaryIndex();
     $headers = $translator->createHeadersFromIndexes($indexes);
     // Check that 4 different header key/value pairs are created, with the correct values.
     $this->assertEquals(4, count($headers));
     $this->assertEquals(['x-riak-index-foo_bin', 'bar'], $headers[0]);
     $this->assertEquals(['x-riak-index-foo_bin', 'baz'], $headers[1]);
     $this->assertEquals(['x-riak-index-foo_int', '42'], $headers[2]);
     $this->assertEquals(['x-riak-index-foo_int', '50'], $headers[3]);
 }
Example #2
0
 /**
  * Prepares the request headers
  *
  * @return $this
  */
 protected function prepareRequestHeaders()
 {
     $curl_headers = [];
     foreach ($this->headers as $key => $value) {
         $curl_headers[] = sprintf('%s: %s', $key, $value);
     }
     // if we have an object, set appropriate object headers
     $object = $this->command->getObject();
     if ($object) {
         if ($object->getVclock()) {
             $curl_headers[] = sprintf('%s: %s', static::VCLOCK_KEY, $object->getVclock());
         }
         if ($object->getContentType()) {
             $charset = '';
             if ($object->getCharset()) {
                 $charset = sprintf('; charset=%s', $object->getCharset());
             }
             $curl_headers[] = sprintf('%s: %s', static::CONTENT_TYPE_KEY, $object->getContentType(), $charset);
         }
         // setup index headers
         $translator = new Api\Http\Translator\SecondaryIndex();
         $indexHeaders = $translator->createHeadersFromIndexes($object->getIndexes());
         foreach ($indexHeaders as $value) {
             $curl_headers[] = sprintf('%s: %s', $value[0], $value[1]);
         }
         // setup metadata headers
         foreach ($object->getMetaData() as $key => $value) {
             $curl_headers[] = sprintf('%s%s: %s', static::METADATA_PREFIX, $key, $value);
         }
     }
     // set the request headers on the connection
     $this->options[CURLOPT_HTTPHEADER] = $curl_headers;
     // dump local headers to start fresh
     $this->headers = [];
     return $this;
 }