Class: Uricp::Strategy::PipedRemoteGet
- Inherits:
-
Object
- Object
- Uricp::Strategy::PipedRemoteGet
show all
- Includes:
- Common
- Defined in:
- lib/uricp/strategy/piped_remote_get.rb
Constant Summary
Constants included
from Common
Common::PIPE_URI
Instance Attribute Summary
Attributes included from Common
#proposed_options
#options
Instance Method Summary
collapse
Methods included from Common
#all_local_files?, #always_write_sparse?, #compression_required?, #conversion_required?, #encoding, #file_source?, #format_change?, #get_temp_filename, #initialize, #lz4?, #lz4_source?, #proposed_path, #qcow2?, #raw_target?, #segmented?, #sequence_complete?, #supported_source?, #temp_uri, #unsupported_transfer
#authentication, #curl_command, #curl_download_to_pipe, #curl_manifest, #curl_upload_from, #from, #from=, #http_authentication?, #to, #to=
Instance Method Details
#appropriate? ⇒ Boolean
8
9
10
11
12
13
14
15
16
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 8
def appropriate?
case from.scheme
when 'http', 'https'
return proposal unless sequence_complete?
else
debug "#{self.class.name}: not appropriate"
false
end
end
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 39
def format_peek
options['from_uri'].open() do |u|
encoding(u)
end
rescue OpenURI::HTTPError => e
case e.io.status[0]
when '416'
'raw'
else
raise
end
rescue SocketError => e
raise SocketError, options['from_uri'].to_s+" inaccessible: "+e.message
end
|
72
73
74
75
76
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 72
def
={'Range' => 'bytes=0-7'}
['X-Auth-Token'] = options['authenticator'].call if http_authentication?
end
|
#proposal ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 20
def proposal
@proposed_options = options.dup
@proposed_options['from_uri'] = PIPE_URI
if conversion_required?
@proposed_options['source-format'] = format_peek
if @proposed_options['source-format'] == @proposed_options['target-format']
@proposed_options.delete('source-format')
@proposed_options.delete('target-format')
end
end
if options['max-cache'] &&
size_peek.to_i > options['max-cache'].to_i
@proposed_options.delete('cache')
@proposed_options.delete('cache_name')
@proposed_options.delete('max-cache')
end
self
end
|
#size_peek ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/uricp/strategy/piped_remote_get.rb', line 54
def size_peek
=
['Range'] = 'bytes=0-0'
options['from_uri'].open() do |u|
match = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(u.meta['content-range'])
match && match[3].to_i
end
rescue OpenURI::HTTPError => e
case e.io.status[0]
when '416'
0
else
raise
end
rescue SocketError => e
raise SocketError, options['from_uri'].to_s+" inaccessible: "+e.message
end
|