deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [1/2] git commit: Fixes for blob streaming GET /bucket/blob/content
Date Tue, 07 Aug 2012 15:20:38 GMT
Updated Branches:
  refs/heads/master 2dbdeb7ac -> 34cf99b76


Fixes for blob streaming GET /bucket/blob/content


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/a7afbc70
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/a7afbc70
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/a7afbc70

Branch: refs/heads/master
Commit: a7afbc70a0e7e33ffb34523efc92870fe92a4f56
Parents: 2dbdeb7
Author: marios <marios@redhat.com>
Authored: Tue Aug 7 14:52:41 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Tue Aug 7 18:17:06 2012 +0300

----------------------------------------------------------------------
 server/lib/deltacloud/collections/buckets.rb       |    2 +-
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |    3 +++
 .../lib/deltacloud/helpers/blob_stream_helper.rb   |   10 ++++------
 3 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7afbc70/server/lib/deltacloud/collections/buckets.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/buckets.rb b/server/lib/deltacloud/collections/buckets.rb
index b7b3729..bb2a805 100644
--- a/server/lib/deltacloud/collections/buckets.rb
+++ b/server/lib/deltacloud/collections/buckets.rb
@@ -258,7 +258,7 @@ module Deltacloud::Collections
             @blob = driver.blob(credentials, { :id => params[:blob_id], 'bucket' =>
params[:id]})
             if @blob
               params['content_length'] = @blob.content_length
-              params['content_type'] = @blob.content_type
+              params['content_type'] = (@blob.content_type.nil? || @blob.content_type ==
"")? "application/octet-stream" : @blob.content_type
               params['content_disposition'] = "attachment; filename=#{@blob.id}"
               BlobStream.call(self, credentials, params)
             else

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7afbc70/server/lib/deltacloud/drivers/mock/mock_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 4249a95..2f0d7eb 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -388,6 +388,8 @@ module Deltacloud::Drivers::Mock
     def blob_data(credentials, bucket_id, blob_id, opts = {})
       check_credentials(credentials)
       if blob = @client.load(:blobs, blob_id)
+        #give event machine a chance
+        sleep 1
         blob[:content].split('').each {|part| yield part}
       end
     end
@@ -406,6 +408,7 @@ module Deltacloud::Drivers::Mock
         :user_metadata => BlobHelper::rename_metadata_headers(blob_meta, ''),
       }
       if blob_data.kind_of? Hash
+        blob_data[:tempfile].rewind
         blob.merge!({
           :content_length => blob_data[:tempfile].length,
           :content_type => blob_data[:type],

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7afbc70/server/lib/deltacloud/helpers/blob_stream_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/blob_stream_helper.rb b/server/lib/deltacloud/helpers/blob_stream_helper.rb
index 8567543..dc1d230 100644
--- a/server/lib/deltacloud/helpers/blob_stream_helper.rb
+++ b/server/lib/deltacloud/helpers/blob_stream_helper.rb
@@ -25,10 +25,7 @@ begin
     AsyncResponse = [-1, {}, []].freeze
     def self.call(context, credentials, params)
      body = DeferrableBody.new
-      #Get the headers out asap. Don't specify a content-type let
-      #the client guess and if they can't they SHOULD default to
-      #'application/octet-stream' anyway as per:
-      #http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1
+      #Get the headers out asap.
       EM.next_tick { context.env['async.callback'].call [200, {
         'Content-Type' => "#{params['content_type']}",
         'Content-Disposition' => params["content_disposition"],
@@ -36,9 +33,9 @@ begin
       }
       #call the driver from here. the driver method yields for every chunk
       #of blob it receives. Then use body.call to write that chunk as received.
-      context.driver.blob_data(credentials, params[:id], params[:blob_id], params) {|chunk|
body.call ["#{chunk}"]} #close blob_data block
+      context.driver.blob_data(credentials, params[:id], params[:blob_id], params) {|chunk|
body.call [chunk]} #close blob_data block
       body.succeed
-      AsyncResponse # Tell Thin to not close connection & work other requests
+      AsyncResponse.dup # Tell Thin to not close connection & work other requests
     end
   end
 
@@ -54,6 +51,7 @@ begin
     def each(&blk)
       @body_callback = blk
     end
+
   end
 rescue LoadError => e
   # EventMachine isn't available, disable blob streaming


Mime
View raw message