This repository was archived by the owner on Feb 28, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ raise 'Patch already integrated into buildr code' unless Buildr ::VERSION . to_s == '1.5.6'
2
+
3
+ class URI ::HTTP
4
+ private
5
+
6
+ def write_internal ( options , &block )
7
+ options ||= { }
8
+ connect do |http |
9
+ trace "Uploading to #{ path } "
10
+ http . read_timeout = 500
11
+ content = StringIO . new
12
+ while chunk = yield ( RW_CHUNK_SIZE )
13
+ content << chunk
14
+ end
15
+ headers = { 'Content-MD5' => Digest ::MD5 . hexdigest ( content . string ) , 'Content-Type' => 'application/octet-stream' , 'User-Agent' => "Buildr-#{ Buildr ::VERSION } " }
16
+ request = Net ::HTTP ::Put . new ( request_uri . empty? ? '/' : request_uri , headers )
17
+ request . basic_auth URI . decode ( self . user ) , URI . decode ( self . password ) if self . user
18
+ response = nil
19
+ with_progress_bar options [ :progress ] , path . split ( '/' ) . last , content . size do |progress |
20
+ request . content_length = content . size
21
+ content . rewind
22
+ stream = Object . new
23
+ class << stream ;
24
+ self ;
25
+ end . send :define_method , :read do |*args |
26
+ bytes = content . read ( *args )
27
+ progress << bytes if bytes
28
+ bytes
29
+ end
30
+ request . body_stream = stream
31
+ response = http . request ( request )
32
+ end
33
+
34
+ case response
35
+ when Net ::HTTPRedirection
36
+ # Try to download from the new URI, handle relative redirects.
37
+ trace "Redirected to #{ response [ 'Location' ] } "
38
+ content . rewind
39
+ return ( self + URI . parse ( response [ 'location' ] ) ) . write_internal ( options ) { |bytes | content . read ( bytes ) }
40
+ when Net ::HTTPSuccess
41
+ else
42
+ raise RuntimeError , "Failed to upload #{ self } : #{ response . message } "
43
+ end
44
+ end
45
+ end
46
+ end
You can’t perform that action at this time.
0 commit comments