incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r1024448 - /incubator/deltacloud/trunk/server/lib/deltacloud/helpers/blob_stream.rb
Date Tue, 19 Oct 2010 22:46:38 GMT
Author: lutter
Date: Tue Oct 19 22:46:37 2010
New Revision: 1024448

URL: http://svn.apache.org/viewvc?rev=1024448&view=rev
Log:
Disable blob streaming when not running under Thin

Patch by Benjamin Browning <bbrowning@redhat.com>

Fixes JIRA https://issues.apache.org/jira/browse/DTACLOUD-6

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/blob_stream.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/blob_stream.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/blob_stream.rb?rev=1024448&r1=1024447&r2=1024448&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/blob_stream.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/blob_stream.rb Tue Oct 19 22:46:37
2010
@@ -15,37 +15,46 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-#--
-# based on the example from http://macournoyer.com/blog/2009/06/04/pusher-and-async-with-thin/
-#--
-require 'eventmachine'
-class BlobStream
-  AsyncResponse = [-1, {}, []].freeze
-  def self.call(env, 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
-    EM.next_tick { env['async.callback'].call [200, {'Content-Type' => "#{params['content_type']}",
'Content-Length' => "#{params['content_length']}"}, body] }
-    #call the driver from here. the driver method yields for every chunk of blob it receives.
We then
-    #use body.call to write that chunk as received.
-    driver.blob_data(credentials, params[:bucket], params[:blob], params) {|chunk| body.call
["#{chunk}"]} #close blob_data block
-    body.succeed
-    AsyncResponse # Tells Thin to not close the connection and continue it's work on other
request
+begin
+  require 'eventmachine'
+  #--
+  # based on the example from http://macournoyer.com/blog/2009/06/04/pusher-and-async-with-thin/
+  #--
+  class BlobStream
+    AsyncResponse = [-1, {}, []].freeze
+    def self.call(env, 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
+      EM.next_tick { env['async.callback'].call [200, {'Content-Type' => "#{params['content_type']}",
'Content-Length' => "#{params['content_length']}"}, body] }
+      #call the driver from here. the driver method yields for every chunk of blob it receives.
We then
+      #use body.call to write that chunk as received.
+      driver.blob_data(credentials, params[:bucket], params[:blob], params) {|chunk| body.call
["#{chunk}"]} #close blob_data block
+      body.succeed
+      AsyncResponse # Tells Thin to not close the connection and continue it's work on other
request
+    end
   end
-end
 
-class DeferrableBody
-  include EventMachine::Deferrable
+  class DeferrableBody
+    include EventMachine::Deferrable
 
-  def call(body)
-    body.each do |chunk|
-      @body_callback.call(chunk)
+    def call(body)
+      body.each do |chunk|
+        @body_callback.call(chunk)
+      end
     end
-  end
 
-  def each(&blk)
-    @body_callback = blk
+    def each(&blk)
+      @body_callback = blk
+    end
+  end
+rescue LoadError => e
+  # EventMachine isn't available, disable blob streaming
+  class BlobStream
+    def self.call(env, credentials, params)
+      raise NotImplementedError.new("Blob streaming is only supported under Thin")
+    end
   end
 end



Mime
View raw message