swift_client 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/swift_client.rb CHANGED
@@ -93,7 +93,12 @@ class SwiftClient
93
93
  mime_type = MIME::Types.of(object_name).first
94
94
 
95
95
  extended_headers = (headers || {}).dup
96
- extended_headers["Content-Type"] ||= mime_type.content_type if mime_type
96
+
97
+ unless find_header_key(extended_headers, "Content-Type")
98
+ extended_headers["Content-Type"] = mime_type.content_type if mime_type
99
+ extended_headers["Content-Type"] ||= "application/octet-stream"
100
+ end
101
+
97
102
  extended_headers["Transfer-Encoding"] = "chunked"
98
103
 
99
104
  request :put, "/#{container_name}/#{object_name}", :body_stream => data_or_io.respond_to?(:read) ? data_or_io : StringIO.new(data_or_io), :headers => extended_headers
@@ -153,6 +158,10 @@ class SwiftClient
153
158
 
154
159
  private
155
160
 
161
+ def find_header_key(headers, key)
162
+ headers.keys.detect { |k| k.downcase == key.downcase }
163
+ end
164
+
156
165
  def request(method, path, opts = {})
157
166
  headers = (opts[:headers] || {}).dup
158
167
  headers["X-Auth-Token"] = auth_token
@@ -1,5 +1,5 @@
1
1
 
2
2
  class SwiftClient
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
 
@@ -131,11 +131,23 @@ class SwiftClientTest < MiniTest::Test
131
131
  end
132
132
 
133
133
  def test_put_object
134
- stub_request(:put, "https://example.com/v1/AUTH_account/container/object").with(:body => "data", :headers => { "Transfer-Encoding" => "chunked", "Accept" => "application/json", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
134
+ stub_request(:put, "https://example.com/v1/AUTH_account/container/object").with(:body => "data", :headers => { "Transfer-Encoding" => "chunked", "Content-Type" => "application/octet-stream", "Accept" => "application/json", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
135
135
 
136
136
  assert_equal 201, @swift_client.put_object("object", "data", "container", "X-Object-Meta-Test" => "Test").code
137
137
  end
138
138
 
139
+ def test_put_object_without_mime_type
140
+ stub_request(:put, "https://example.com/v1/AUTH_account/container/object.jpg").with(:body => "data", :headers => { "Transfer-Encoding" => "chunked", "Accept" => "application/json", "Content-Type" => "image/jpeg", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
141
+
142
+ assert_equal 201, @swift_client.put_object("object.jpg", "data", "container", "X-Object-Meta-Test" => "Test").code
143
+ end
144
+
145
+ def test_put_object_with_mime_type
146
+ stub_request(:put, "https://example.com/v1/AUTH_account/container/object.jpg").with(:body => "data", :headers => { "Transfer-Encoding" => "chunked", "Accept" => "application/json", "Content-Type" => "content/type", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
147
+
148
+ assert_equal 201, @swift_client.put_object("object.jpg", "data", "container", "X-Object-Meta-Test" => "Test", "Content-Type" => "content/type").code
149
+ end
150
+
139
151
  def test_put_object_with_io
140
152
  stub_request(:put, "https://example.com/v1/AUTH_account/container/object").with(:body => "data", :headers => { "Transfer-Encoding" => "chunked", "Accept" => "application/json", "X-Auth-Token" => "Token", "X-Object-Meta-Test" => "Test" }).to_return(:status => 201, :body => "", :headers => {})
141
153
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-05 00:00:00.000000000 Z
12
+ date: 2015-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty