Class: BlobStreamIO

Inherits:
Object
  • Object
show all
Defined in:
lib/deltacloud/helpers/blob_stream_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ BlobStreamIO

Returns a new instance of BlobStreamIO.



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/deltacloud/helpers/blob_stream_helper.rb', line 185

def initialize(request)
  @client_request = request
  @size = 0
  bucket, blob = parse_bucket_blob(request.env["PATH_INFO"])
  user, password = parse_credentials(request.env['HTTP_AUTHORIZATION'])
  content_type = request.env['CONTENT_TYPE'] || ""
  #deal with blob_metadata: (X-Deltacloud-Blobmeta-name: value)
  user_meta = BlobHelper::(request.env)
  @content_length = request.env['CONTENT_LENGTH']
  @http, provider_request = Deltacloud::API.driver.blob_stream_connection({:user=>user,
     :password=>password, :bucket=>bucket, :blob=>blob, :metadata=> user_meta,
     :content_type=>content_type, :content_length=>@content_length, :context=>request })
  @content_length = @content_length.to_i #for comparison of size in '<< (data)'
  @sock = @http.request(provider_request, nil, true)
end

Instance Attribute Details

#providerObject

Returns the value of attribute provider.



184
185
186
# File 'lib/deltacloud/helpers/blob_stream_helper.rb', line 184

def provider
  @provider
end

#sizeObject

Returns the value of attribute size.



184
185
186
# File 'lib/deltacloud/helpers/blob_stream_helper.rb', line 184

def size
  @size
end

#sockObject

Returns the value of attribute sock.



184
185
186
# File 'lib/deltacloud/helpers/blob_stream_helper.rb', line 184

def sock
  @sock
end

Class Method Details

.is_put_blob(request = nil) ⇒ Object

use the Request.env hash (populated by the ThinParser) to determine whether this is a post blob operation. By definition, only get here with a body of > 112kbytes - thin/lib/thin/request.rb:12 MAX_BODY = 1024 * (80 + 32)



222
223
224
225
226
227
228
229
230
# File 'lib/deltacloud/helpers/blob_stream_helper.rb', line 222

def self.is_put_blob(request = nil)
  path = request.env['PATH_INFO']
  method = request.env['REQUEST_METHOD']
  if ( path =~ /^#{Regexp.escape(Deltacloud::API.settings.root_url)}\/buckets/ && method == 'PUT' )
    return true
  else
    return false
  end
end

Instance Method Details

#<<(data) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/deltacloud/helpers/blob_stream_helper.rb', line 200

def << (data)
  @sock.write(data)
  @size += data.length
  if (@size >= @content_length)
    result = @http.end_request
    if result.is_a?(Net::HTTPSuccess)
      @client_request.env["BLOB_SUCCESS"] = "true"
      if BlobHelper.segmented_blob_op_type(@client_request) == "segment"
        @client_request.env["BLOB_SEGMENT_ID"] = Deltacloud::API.driver.blob_segment_id(@client_request, result)
      end
    else
      @client_request.env["BLOB_FAIL"] = result.body
    end
  end
end

#rewindObject



216
217
# File 'lib/deltacloud/helpers/blob_stream_helper.rb', line 216

def rewind
end