Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby Net:HTTP chunked transfer
require 'uri'
require 'net/http'
class Chunked
def initialize(data, chunk_size)
@size = chunk_size
if data.respond_to? :read
@file = data
end
end
def read(foo)
if @file
@file.read(@size)
end
end
def eof!
@file.eof!
end
def eof?
@file.eof?
end
end
parsed = URI::parse(@storage_url)
conn = Net::HTTP.new(parsed.host, parsed.port)
fp = File::open('test.txt')
parsed.path += '/foo/test.txt'
chunked = Chunked.new(fp, 5)
request = Net::HTTP::Put.new parsed.request_uri, {'x-auth-token' => @auth_token, 'Transfer-Encoding' => 'chunked', 'content-type' => 'text/plain'}
request.body_stream = chunked
conn.start do |http|
http.request(request)
end
fp.close
@zhouguangming

Not work for me. Puma can not parse the request.

2014-04-22 16:53:00 +0800: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2014-04-22 16:53:00 +0800: ENV: {"rack.version"=>[1, 2], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "CONTENT_TYPE"=>"text/plain", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"2.8.1", "GATEWAY_INTERFACE"=>"CGI/1.2"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.