|
25 | 25 | # to the underlying lib this stuff will need updating.
|
26 | 26 |
|
27 | 27 | module S3
|
28 |
| - class AWSAuthConnection |
| 28 | + class AWSAuthConnection |
29 | 29 |
|
30 |
| - def make_http(bucket='', host='', proxy_host=nil, proxy_port=nil, proxy_user=nil, proxy_pass=nil) |
| 30 | + def make_http(bucket='', host='', proxy_host=nil, proxy_port=nil, proxy_user=nil, proxy_pass=nil) |
31 | 31 |
|
32 |
| - # build the domain based on the calling format |
33 |
| - server = '' |
34 |
| - if host != '' |
35 |
| - server = host |
36 |
| - elsif bucket.empty? |
37 |
| - # for a bucketless request (i.e. list all buckets) |
38 |
| - # revert to regular domain case since this operation |
39 |
| - # does not make sense for vanity domains |
40 |
| - server = @server |
41 |
| - elsif @calling_format == CallingFormat::SUBDOMAIN |
42 |
| - server = "#{bucket}.#{@server}" |
43 |
| - elsif @calling_format == CallingFormat::VANITY |
44 |
| - server = bucket |
45 |
| - else |
46 |
| - server = @server |
47 |
| - end |
48 |
| - # automatically does the right thing when no proxy |
49 |
| - http = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).new(server, @port) |
50 |
| - #http = Net::HTTP.new(server, @port) |
51 |
| - http.use_ssl = @is_secure |
52 |
| - http.verify_mode=@verify_mode |
53 |
| - http.ca_file=@ca_file |
54 |
| - http.ca_path=@ca_path |
55 |
| - http.start |
56 |
| - return http |
| 32 | + # build the domain based on the calling format |
| 33 | + server = '' |
| 34 | + if host != '' |
| 35 | + server = host |
| 36 | + elsif bucket.empty? |
| 37 | + # for a bucketless request (i.e. list all buckets) |
| 38 | + # revert to regular domain case since this operation |
| 39 | + # does not make sense for vanity domains |
| 40 | + server = @server |
| 41 | + elsif @calling_format == CallingFormat::SUBDOMAIN |
| 42 | + server = "#{bucket}.#{@server}" |
| 43 | + elsif @calling_format == CallingFormat::VANITY |
| 44 | + server = bucket |
| 45 | + else |
| 46 | + server = @server |
57 | 47 | end
|
58 |
| - |
59 |
| - # add support for streaming the response body to an IO stream |
60 |
| - alias __make_request__ make_request |
61 |
| - def make_request(method, bucket='', key='', path_args={}, headers={}, data='', metadata={}, streamOut=nil) |
62 |
| - # build the path based on the calling format |
63 |
| - path = '' |
64 |
| - if (not bucket.empty?) and (@calling_format == CallingFormat::REGULAR) |
65 |
| - path << "/#{bucket}" |
66 |
| - end |
67 |
| - # add the slash after the bucket regardless |
68 |
| - # the key will be appended if it is non-empty |
69 |
| - path << "/#{key}" |
70 |
| - |
71 |
| - # build the path_argument string |
72 |
| - # add the ? in all cases since |
73 |
| - # signature and credentials follow path args |
74 |
| - path << '?' |
75 |
| - path << S3.path_args_hash_to_string(path_args) |
76 |
| - |
77 |
| - req = method_to_request_class(method).new("#{path}") |
78 |
| - |
79 |
| - set_headers(req, headers) |
80 |
| - set_headers(req, metadata, METADATA_PREFIX) |
81 |
| - set_headers(req, {'Connection' => 'keep-alive', 'Keep-Alive' => '300'}) |
82 |
| - |
83 |
| - set_aws_auth_header(req, @aws_access_key_id, @aws_secret_access_key, bucket, key, path_args) |
84 |
| - |
85 |
| - http = $S3syncHttp |
86 |
| - |
87 |
| - if req.request_body_permitted? |
88 |
| - return http.request(req, data, streamOut) |
89 |
| - else |
90 |
| - return http.request(req, nil, streamOut) |
91 |
| - end |
| 48 | + # automatically does the right thing when no proxy |
| 49 | + http = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).new(server, @port) |
| 50 | + #http = Net::HTTP.new(server, @port) |
| 51 | + http.use_ssl = @is_secure |
| 52 | + http.verify_mode=@verify_mode |
| 53 | + http.ca_file=@ca_file |
| 54 | + http.ca_path=@ca_path |
| 55 | + http.start |
| 56 | + return http |
| 57 | + end |
| 58 | + |
| 59 | + # add support for streaming the response body to an IO stream |
| 60 | + alias __make_request__ make_request |
| 61 | + def make_request(method, bucket='', key='', path_args={}, headers={}, data='', metadata={}, streamOut=nil) |
| 62 | + # build the path based on the calling format |
| 63 | + path = '' |
| 64 | + if (not bucket.empty?) and (@calling_format == CallingFormat::REGULAR) |
| 65 | + path << "/#{bucket}" |
92 | 66 | end
|
93 |
| - |
94 |
| - # a "get" operation that sends the body to an IO stream |
95 |
| - def get_stream(bucket, key, headers={}, streamOut=nil) |
96 |
| - return GetResponse.new(make_request('GET', bucket, CGI::escape(key), {}, headers, '', {}, streamOut)) |
97 |
| - end |
98 |
| - |
99 |
| - # a "get" operation that sends the body to an IO stream |
100 |
| - def get_query_stream(bucket, key, path_args={}, headers={}, streamOut=nil) |
101 |
| - return GetResponse.new(make_request('GET', bucket, CGI::escape(key), path_args, headers, '', {}, streamOut)) |
102 |
| - end |
| 67 | + # add the slash after the bucket regardless |
| 68 | + # the key will be appended if it is non-empty |
| 69 | + path << "/#{key}" |
| 70 | + |
| 71 | + # build the path_argument string |
| 72 | + # add the ? in all cases since |
| 73 | + # signature and credentials follow path args |
| 74 | + path << '?' |
| 75 | + path << S3.path_args_hash_to_string(path_args) |
| 76 | + |
| 77 | + req = method_to_request_class(method).new("#{path}") |
| 78 | + |
| 79 | + set_headers(req, headers) |
| 80 | + set_headers(req, metadata, METADATA_PREFIX) |
| 81 | + set_headers(req, {'Connection' => 'keep-alive', 'Keep-Alive' => '300'}) |
103 | 82 |
|
104 |
| - def head(bucket, key=nil, headers={}) |
105 |
| - return GetResponse.new(make_request('HEAD', bucket, CGI::escape(key), {}, headers, '', {})) |
106 |
| - end |
107 |
| - undef create_bucket |
108 |
| - def create_bucket(bucket, object) |
109 |
| - object = S3Object.new(object) if not object.instance_of? S3Object |
110 |
| - return Response.new( |
111 |
| - make_request('PUT', bucket, '', {}, {}, object.data, object.metadata) |
112 |
| - ) |
| 83 | + set_aws_auth_header(req, @aws_access_key_id, @aws_secret_access_key, bucket, key, path_args) |
| 84 | + |
| 85 | + http = $S3syncHttp |
| 86 | + |
| 87 | + if req.request_body_permitted? |
| 88 | + return http.request(req, data, streamOut) |
| 89 | + else |
| 90 | + return http.request(req, nil, streamOut) |
113 | 91 | end
|
114 |
| - # no, because internally the library does not support the header,wait,body paradigm, so this is useless |
115 |
| - #alias __put__ put |
116 |
| - #def put(bucket, key, object, headers={}) |
117 |
| - # headers['Expect'] = "100-continue" |
118 |
| - # __put__(bucket, key, object, headers) |
119 |
| - #end |
120 |
| - |
| 92 | + end |
| 93 | + |
| 94 | + # a "get" operation that sends the body to an IO stream |
| 95 | + def get_stream(bucket, key, headers={}, streamOut=nil) |
| 96 | + return GetResponse.new(make_request('GET', bucket, CGI::escape(key), {}, headers, '', {}, streamOut)) |
| 97 | + end |
| 98 | + |
| 99 | + # a "get" operation that sends the body to an IO stream |
| 100 | + def get_query_stream(bucket, key, path_args={}, headers={}, streamOut=nil) |
| 101 | + return GetResponse.new(make_request('GET', bucket, CGI::escape(key), path_args, headers, '', {}, streamOut)) |
| 102 | + end |
| 103 | + |
| 104 | + def head(bucket, key=nil, headers={}) |
| 105 | + return GetResponse.new(make_request('HEAD', bucket, CGI::escape(key), {}, headers, '', {})) |
| 106 | + end |
| 107 | + undef create_bucket |
| 108 | + def create_bucket(bucket, object) |
| 109 | + object = S3Object.new(object) if not object.instance_of? S3Object |
| 110 | + return Response.new( |
| 111 | + make_request('PUT', bucket, '', {}, {}, object.data, object.metadata) |
| 112 | + ) |
| 113 | + end |
| 114 | + # no, because internally the library does not support the header,wait,body paradigm, so this is useless |
| 115 | + #alias __put__ put |
| 116 | + #def put(bucket, key, object, headers={}) |
| 117 | + # headers['Expect'] = "100-continue" |
| 118 | + # __put__(bucket, key, object, headers) |
| 119 | + #end |
| 120 | + |
121 | 121 |
|
122 |
| - # allow ssl validation |
123 |
| - attr_accessor :verify_mode |
124 |
| - attr_accessor :ca_path |
125 |
| - attr_accessor :ca_file |
126 |
| - |
127 |
| - end |
128 |
| - module CallingFormat |
129 |
| - def CallingFormat.string_to_format(s) |
130 |
| - case s |
131 |
| - when 'REGULAR' |
132 |
| - return CallingFormat::REGULAR |
133 |
| - when 'SUBDOMAIN' |
134 |
| - return CallingFormat::SUBDOMAIN |
135 |
| - when 'VANITY' |
136 |
| - return CallingFormat::VANITY |
137 |
| - else |
138 |
| - raise "Unsupported calling format #{s}" |
139 |
| - end |
| 122 | + # allow ssl validation |
| 123 | + attr_accessor :verify_mode |
| 124 | + attr_accessor :ca_path |
| 125 | + attr_accessor :ca_file |
| 126 | + |
| 127 | + end |
| 128 | + module CallingFormat |
| 129 | + def CallingFormat.string_to_format(s) |
| 130 | + case s |
| 131 | + when 'REGULAR' |
| 132 | + return CallingFormat::REGULAR |
| 133 | + when 'SUBDOMAIN' |
| 134 | + return CallingFormat::SUBDOMAIN |
| 135 | + when 'VANITY' |
| 136 | + return CallingFormat::VANITY |
| 137 | + else |
| 138 | + raise "Unsupported calling format #{s}" |
140 | 139 | end
|
141 |
| - end |
142 |
| - |
| 140 | + end |
| 141 | + end |
| 142 | + |
143 | 143 | end
|
0 commit comments