Refactor the put_request method to have a return value

This commit is contained in:
2018-05-09 16:01:14 +02:00
parent 709f63555d
commit 639c3724f0
2 changed files with 15 additions and 17 deletions
+7 -8
View File
@@ -141,7 +141,7 @@ module RemoteStorage
server.halt 412, "Precondition Failed" unless existing_metadata.empty? server.halt 412, "Precondition Failed" unless existing_metadata.empty?
end end
etag, timestamp = do_put_request_and_return_etag_and_last_modified(url, data, content_type) etag, timestamp = do_put_request(url, data, content_type)
metadata = { metadata = {
e: etag, e: etag,
@@ -392,14 +392,13 @@ module RemoteStorage
def do_put_request(url, data, content_type) def do_put_request(url, data, content_type)
deal_with_unauthorized_requests do deal_with_unauthorized_requests do
RestClient.put(url, data, default_headers.merge({content_type: content_type})) res = RestClient.put(url, data, default_headers.merge({content_type: content_type}))
end
end
def do_put_request_and_return_etag_and_last_modified(url, data, content_type) return [
res = do_put_request(url, data, content_type) res.headers[:etag],
timestamp_for(res.headers[:last_modified])
return [res.headers[:etag], timestamp_for(res.headers[:last_modified])] ]
end
end end
def do_get_request(url, &block) def do_get_request(url, &block)
+6 -7
View File
@@ -21,16 +21,15 @@ module RemoteStorage
authorization_headers = authorization_headers_for( authorization_headers = authorization_headers_for(
"PUT", url, md5, content_type "PUT", url, md5, content_type
).merge({ "Content-Type" => content_type, "Content-Md5" => md5 }) ).merge({ "Content-Type" => content_type, "Content-Md5" => md5 })
RestClient.put(url, data, authorization_headers) res = RestClient.put(url, data, authorization_headers)
end
end
def do_put_request_and_return_etag_and_last_modified(url, data, content_type)
res = do_put_request(url, data, content_type)
# S3 does not return a Last-Modified response header on PUTs # S3 does not return a Last-Modified response header on PUTs
head_res = do_head_request(url) head_res = do_head_request(url)
return [res.headers[:etag].delete('"'), timestamp_for(head_res.headers[:last_modified])] return [
res.headers[:etag].delete('"'),
timestamp_for(head_res.headers[:last_modified])
]
end
end end
def do_get_request(url, &block) def do_get_request(url, &block)