net_dav 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +20 -3
- data/VERSION +1 -1
- data/lib/net/dav.rb +58 -16
- data/net_dav.gemspec +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -6,6 +6,10 @@ Installing the gem:
|
|
6
6
|
|
7
7
|
gem install net_dav
|
8
8
|
|
9
|
+
and if you want acceleration for large files (from 4MB/s to 20MB/s in my setup):
|
10
|
+
|
11
|
+
gem install curb
|
12
|
+
|
9
13
|
If you're having install issues with nokogiri on Mac OS X read
|
10
14
|
http://wiki.github.com/tenderlove/nokogiri/what-to-do-if-libxml2-is-being-a-jerk
|
11
15
|
|
@@ -17,6 +21,19 @@ http://wiki.github.com/tenderlove/nokogiri/what-to-do-if-libxml2-is-being-a-jerk
|
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
(Note that if you want to use "." to refer to the origin URL, it should
|
25
|
+
end with a slash, otherwise it is assumed that the last component is a file
|
26
|
+
and "." will refer to the parent.)
|
27
|
+
|
28
|
+
== Performance
|
29
|
+
|
30
|
+
This should be threadsafe if you use a different Net::DAV object
|
31
|
+
for each thread.
|
32
|
+
Check out script/multi-test for a multi-threaded application.
|
33
|
+
|
34
|
+
Installing the +curb+ gem will gain speedup with large files, but currently
|
35
|
+
is much slower doing many small +get+ operations. If your usecase is the
|
36
|
+
latter and you have +curb+ installed, you can disable its use by passing the
|
37
|
+
:curl => false
|
38
|
+
option to Net::DAV::start or Net::DAV::new .
|
39
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/net/dav.rb
CHANGED
@@ -11,6 +11,7 @@ end
|
|
11
11
|
module Net #:nodoc:
|
12
12
|
# Implement a WebDAV client
|
13
13
|
class DAV
|
14
|
+
MAX_REDIRECTS = 10
|
14
15
|
class NetHttpHandler
|
15
16
|
attr_writer :user, :pass
|
16
17
|
|
@@ -61,8 +62,7 @@ module Net #:nodoc:
|
|
61
62
|
if (@user)
|
62
63
|
req.basic_auth @user, @pass
|
63
64
|
end
|
64
|
-
res =
|
65
|
-
res.value # raises error if not success
|
65
|
+
res = handle_request(req, headers)
|
66
66
|
res
|
67
67
|
end
|
68
68
|
|
@@ -80,8 +80,7 @@ module Net #:nodoc:
|
|
80
80
|
if (@user)
|
81
81
|
req.basic_auth @user, @pass
|
82
82
|
end
|
83
|
-
res =
|
84
|
-
res.value # raises error if not success
|
83
|
+
res = handle_request(req, headers)
|
85
84
|
res
|
86
85
|
end
|
87
86
|
|
@@ -97,12 +96,7 @@ module Net #:nodoc:
|
|
97
96
|
if (@user)
|
98
97
|
req.basic_auth @user, @pass
|
99
98
|
end
|
100
|
-
res =
|
101
|
-
@http.request(req) {|response|
|
102
|
-
response.read_body nil, &block
|
103
|
-
res = response
|
104
|
-
}
|
105
|
-
res.value # raises error if not success
|
99
|
+
res = handle_request(req, headers, MAX_REDIRECTS, &block)
|
106
100
|
res.body
|
107
101
|
end
|
108
102
|
|
@@ -122,20 +116,68 @@ module Net #:nodoc:
|
|
122
116
|
if (@user)
|
123
117
|
req.basic_auth @user, @pass
|
124
118
|
end
|
125
|
-
res =
|
126
|
-
res.value # raises error if not success
|
119
|
+
res = handle_request(req, headers)
|
127
120
|
res
|
128
121
|
end
|
122
|
+
|
123
|
+
def handle_request(req, headers, limit = MAX_REDIRECTS, &block)
|
124
|
+
# You should choose better exception.
|
125
|
+
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
126
|
+
|
127
|
+
response = nil
|
128
|
+
if block
|
129
|
+
@http.request(req) {|res|
|
130
|
+
res.read_body nil, &block
|
131
|
+
response = res
|
132
|
+
}
|
133
|
+
else
|
134
|
+
response = @http.request(req)
|
135
|
+
end
|
136
|
+
case response
|
137
|
+
when Net::HTTPSuccess then response
|
138
|
+
when Net::HTTPRedirection then
|
139
|
+
location = URI.parse(response['location'])
|
140
|
+
if (@uri.scheme != location.scheme ||
|
141
|
+
@uri.host != location.host ||
|
142
|
+
@uri.port != location.port)
|
143
|
+
raise "cannot redirect to a different host #{@uri} => #{location}"
|
144
|
+
end
|
145
|
+
new_req = req.class.new(location.path)
|
146
|
+
new_req.body = req.body
|
147
|
+
new_req.body_stream = req.body_stream
|
148
|
+
headers.each_pair { |key, value| new_req[key] = value } if headers
|
149
|
+
if (@user)
|
150
|
+
new_req.basic_auth @user, @pass
|
151
|
+
end
|
152
|
+
handle_request(new_req, limit - 1, &block)
|
153
|
+
else
|
154
|
+
response.error!
|
155
|
+
end
|
156
|
+
end
|
129
157
|
end
|
130
158
|
|
159
|
+
|
131
160
|
class CurlHandler < NetHttpHandler
|
161
|
+
def make_curl
|
162
|
+
unless @curl
|
163
|
+
@curl = Curl::Easy.new
|
164
|
+
@curl.timeout = @http.read_timeout
|
165
|
+
@curl.follow_location = true
|
166
|
+
@curl.max_redirects = MAX_REDIRECTS
|
167
|
+
end
|
168
|
+
@curl
|
169
|
+
end
|
170
|
+
|
132
171
|
def request_returning_body(verb, path, headers)
|
133
172
|
raise "unkown returning_body verb #{verb}" unless verb == :get
|
134
173
|
url = @uri.merge(path)
|
135
|
-
curl =
|
174
|
+
curl = make_curl
|
175
|
+
curl.url = url.to_s
|
136
176
|
headers.each_pair { |key, value| curl.headers[key] = value } if headers
|
137
177
|
if (@user)
|
138
|
-
curl.
|
178
|
+
curl.userpwd = "#{@user}:#{@pass}"
|
179
|
+
else
|
180
|
+
curl.userpwd = nil
|
139
181
|
end
|
140
182
|
res = nil
|
141
183
|
if block_given?
|
@@ -283,8 +325,8 @@ module Net #:nodoc:
|
|
283
325
|
# object will *not* contain a (meaningful) body.
|
284
326
|
|
285
327
|
def get(path, &block)
|
286
|
-
@handler.request_returning_body(:get, path, nil, &block)
|
287
|
-
|
328
|
+
body = @handler.request_returning_body(:get, path, nil, &block)
|
329
|
+
body
|
288
330
|
end
|
289
331
|
|
290
332
|
# Stores the content of a stream to a URL
|
data/net_dav.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{net_dav}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Miron Cuperman"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-31}
|
13
13
|
s.default_executable = %q{dav}
|
14
14
|
s.description = %q{WebDAV client library in the style of Net::HTTP}
|
15
15
|
s.email = %q{c1.github@niftybox.net}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net_dav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miron Cuperman
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-31 00:00:00 -07:00
|
13
13
|
default_executable: dav
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|