Skip to content

Commit

Permalink
Some trivial formatting changes, added docs for custom headers, bumped
Browse files Browse the repository at this point in the history
version.
  • Loading branch information
Marsell Kukuljevic committed Apr 6, 2015
1 parent 1c2f9fe commit 56fc959
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
26 changes: 23 additions & 3 deletions README.md
Expand Up @@ -169,9 +169,9 @@ supports it either.

Changes in 2.0.0
----------------
* MantaClient was moved into the namespace RubyManta::MantaClient. Compatibility
with the namespaceless 1.0.0 MantaClient was maintained, but it may not be
there in the future, so please update your application code.
* MantaClient was moved into the namespace RubyManta::MantaClient.
Compatibility with the namespaceless 1.0.0 MantaClient was maintained, but it
may not be there in the future, so please update your application code.
* Subuser support was added to the client.


Expand Down Expand Up @@ -328,6 +328,26 @@ You can also pass in :origin to most object- and directory-related methods.



Custom headers
--------------

Manta allows additional custom headers to be
[added with an object](https://apidocs.joyent.com/manta/storage-reference.html#custom-headers).
When the object is retrieved, the custom headers are returned as well.

ruby-manta supports this, by adding any :m_* arguments as headers to an object.
For example, to add an 'M-Foobar' header with an object:

```ruby

client.put_object(/john/stor/passwd', 'weak', :m_foobar => 'baz')
```
A reminder when reading back headers (e.g. using get_object()) that header names
are case-insensitive (see RFC 2616). 'M-Foobar' may return as 'm-foobar'.
initialize(manta_host, user, priv_key, _options_)
-------------------------------------------------
Expand Down
10 changes: 7 additions & 3 deletions lib/ruby-manta/manta_client.rb
Expand Up @@ -849,12 +849,14 @@ def attempt(tries, &blk)
end



# :m_some_header becomes "M-Some-Header"
def symbol_to_header(header_symbol)
header_symbol.to_s.split("_").map(&:capitalize).join("-")
header_symbol.to_s.split('_').map(&:capitalize).join('-')
end



# Creates headers to be given to the HTTP client and sent to the Manta
# service. The most important is the Authorization header, without which
# none of this class would work.
Expand Down Expand Up @@ -894,9 +896,11 @@ def gen_headers(opts)
headers.push([ 'Origin', origin ])
end

custom_headers = opts.keys.select{|key| key.to_s.start_with? "m_" }
custom_headers = opts.keys.select { |key| key.to_s.start_with? 'm_' }
unless custom_headers.empty?
headers += custom_headers.map{|header_key| [ symbol_to_header(header_key), opts[header_key] ] }
headers += custom_headers.map do |header_key|
[ symbol_to_header(header_key), opts[header_key] ]
end
end

# add md5 hash when sending data
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-manta/version.rb
@@ -1,3 +1,3 @@
module RubyManta
VERSION = '2.0.1'
VERSION = '2.1.0'
end
3 changes: 1 addition & 2 deletions test/unit/manta_client_test.rb
Expand Up @@ -208,8 +208,7 @@ def test_objects
@@client.put_object(@@test_dir_path + '/obj1', 'bar-data',
:content_type => 'application/wacky',
:durability_level => 3,
:m_zip => "zap"
)
:m_zip => 'zap')

result, headers = @@client.get_object(@@test_dir_path + '/obj1')
assert_equal result, 'bar-data'
Expand Down

0 comments on commit 56fc959

Please sign in to comment.