mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge branch 'master' of git@github.com:geemus/fog
This commit is contained in:
commit
27deaf7a94
6 changed files with 27 additions and 20 deletions
|
@ -33,7 +33,7 @@ unless Fog.mocking?
|
||||||
:host => "#{target_bucket_name}.#{@host}",
|
:host => "#{target_bucket_name}.#{@host}",
|
||||||
:method => 'PUT',
|
:method => 'PUT',
|
||||||
:parser => Fog::Parsers::AWS::S3::CopyObject.new,
|
:parser => Fog::Parsers::AWS::S3::CopyObject.new,
|
||||||
:path => target_object_name
|
:path => CGI.escape(target_object_name)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ unless Fog.mocking?
|
||||||
:headers => {},
|
:headers => {},
|
||||||
:host => "#{bucket_name}.#{@host}",
|
:host => "#{bucket_name}.#{@host}",
|
||||||
:method => 'DELETE',
|
:method => 'DELETE',
|
||||||
:path => object_name
|
:path => CGI.escape(object_name)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ unless Fog.mocking?
|
||||||
:headers => headers,
|
:headers => headers,
|
||||||
:host => "#{bucket_name}.#{@host}",
|
:host => "#{bucket_name}.#{@host}",
|
||||||
:method => 'GET',
|
:method => 'GET',
|
||||||
:path => object_name,
|
:path => CGI.escape(object_name),
|
||||||
:block => block
|
:block => block
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,7 @@ unless Fog.mocking?
|
||||||
:headers => headers,
|
:headers => headers,
|
||||||
:host => "#{bucket_name}.#{@host}",
|
:host => "#{bucket_name}.#{@host}",
|
||||||
:method => 'HEAD',
|
:method => 'HEAD',
|
||||||
:path => object_name
|
:path => CGI.escape(object_name)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ unless Fog.mocking?
|
||||||
:headers => headers,
|
:headers => headers,
|
||||||
:host => "#{bucket_name}.#{@host}",
|
:host => "#{bucket_name}.#{@host}",
|
||||||
:method => 'PUT',
|
:method => 'PUT',
|
||||||
:path => object_name
|
:path => CGI.escape(object_name)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,20 @@ unless Fog.mocking?
|
||||||
|
|
||||||
def initialize(url)
|
def initialize(url)
|
||||||
@uri = URI.parse(url)
|
@uri = URI.parse(url)
|
||||||
@connection = TCPSocket.open(@uri.host, @uri.port)
|
end
|
||||||
if @uri.scheme == 'https'
|
|
||||||
@ssl_context = OpenSSL::SSL::SSLContext.new
|
def connection
|
||||||
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
if @connection && !@connection.closed?
|
||||||
@connection = OpenSSL::SSL::SSLSocket.new(@connection, @ssl_context)
|
@connection
|
||||||
@connection.sync_close = true
|
else
|
||||||
@connection.connect
|
@connection = TCPSocket.open(@uri.host, @uri.port)
|
||||||
|
if @uri.scheme == 'https'
|
||||||
|
@ssl_context = OpenSSL::SSL::SSLContext.new
|
||||||
|
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
|
@connection = OpenSSL::SSL::SSLSocket.new(@connection, @ssl_context)
|
||||||
|
@connection.sync_close = true
|
||||||
|
@connection.connect
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -45,7 +52,7 @@ unless Fog.mocking?
|
||||||
request << "#{key}: #{value}\r\n"
|
request << "#{key}: #{value}\r\n"
|
||||||
end
|
end
|
||||||
request << "\r\n"
|
request << "\r\n"
|
||||||
@connection.write(request)
|
connection.write(request)
|
||||||
|
|
||||||
if params[:body]
|
if params[:body]
|
||||||
if params[:body].is_a?(String)
|
if params[:body].is_a?(String)
|
||||||
|
@ -54,18 +61,18 @@ unless Fog.mocking?
|
||||||
body = params[:body]
|
body = params[:body]
|
||||||
end
|
end
|
||||||
while chunk = body.read(CHUNK_SIZE)
|
while chunk = body.read(CHUNK_SIZE)
|
||||||
@connection.write(chunk)
|
connection.write(chunk)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
response = Fog::Response.new
|
response = Fog::Response.new
|
||||||
response.request = params
|
response.request = params
|
||||||
response.status = @connection.readline[9..11].to_i
|
response.status = connection.readline[9..11].to_i
|
||||||
if params[:expects] && params[:expects] != response.status
|
if params[:expects] && params[:expects] != response.status
|
||||||
error = true
|
error = true
|
||||||
end
|
end
|
||||||
while true
|
while true
|
||||||
data = @connection.readline.chomp!
|
data = connection.readline.chomp!
|
||||||
if data == ""
|
if data == ""
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -89,19 +96,19 @@ unless Fog.mocking?
|
||||||
|
|
||||||
if response.headers['Content-Length']
|
if response.headers['Content-Length']
|
||||||
if error || !params[:block]
|
if error || !params[:block]
|
||||||
body << @connection.read(response.headers['Content-Length'].to_i)
|
body << connection.read(response.headers['Content-Length'].to_i)
|
||||||
else
|
else
|
||||||
remaining = response.headers['Content-Length'].to_i
|
remaining = response.headers['Content-Length'].to_i
|
||||||
while remaining > 0
|
while remaining > 0
|
||||||
params[:block].call(@connection.read([CHUNK_SIZE, remaining].min))
|
params[:block].call(connection.read([CHUNK_SIZE, remaining].min))
|
||||||
remaining -= CHUNK_SIZE;
|
remaining -= CHUNK_SIZE;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif response.headers['Transfer-Encoding'] == 'chunked'
|
elsif response.headers['Transfer-Encoding'] == 'chunked'
|
||||||
while true
|
while true
|
||||||
# 2 == "/r/n".length
|
# 2 == "/r/n".length
|
||||||
chunk_size = @connection.readline.chomp!.to_i(16) + 2
|
chunk_size = connection.readline.chomp!.to_i(16) + 2
|
||||||
chunk = @connection.read(chunk_size)[0...-2]
|
chunk = connection.read(chunk_size)[0...-2]
|
||||||
if error || !params[:block]
|
if error || !params[:block]
|
||||||
body << chunk
|
body << chunk
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue