net_dav 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +6 -1
- data/Rakefile +1 -68
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/net/dav.rb +156 -25
- data/lib/net/dav/item.rb +39 -1
- data/lib/net/dav/version.rb +5 -0
- data/net_dav.gemspec +33 -66
- metadata +104 -75
- data/VERSION +0 -1
- data/spec/fixtures/file.html +0 -1
- data/spec/integration/net_dav_spec.rb +0 -124
- data/spec/integration/webdav_server.rb +0 -87
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 84bab24bbb50aa7f879686a344f6b3109d839099
|
4
|
+
data.tar.gz: 34ed1c83a0cd26ccebd8c00aa4193fb2b97c8796
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c24bc53644936a52deb68c938d600d3b944d4f23fe06dc90d951219a68045be279716b351198368cc1d97d067491a0f72b204346d3c6e0846afb13bb506d33f5
|
7
|
+
data.tar.gz: ab2bcef36d1c28bea11684b472c7ff25a1eda91a8df1809d44d8a999d9d501284ca0231949b7a476dcfdc2adfc44ea9a5e1dd97a5b387bd3dd019e87f8d1b630
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Net::Dav library, in the style of Net::HTTP
|
1
|
+
Net::Dav library, in the style of Net::HTTP {<img src="https://travis-ci.org/devrandom/net_dav.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/devrandom/net_dav]
|
2
2
|
|
3
3
|
== Install
|
4
4
|
|
@@ -42,3 +42,8 @@ latter and you have +curb+ installed, you can disable its use by passing the
|
|
42
42
|
:curl => false
|
43
43
|
option to Net::DAV::start or Net::DAV::new .
|
44
44
|
|
45
|
+
== Other
|
46
|
+
|
47
|
+
Thanks go to Thomas ( https://github.com/thomasfl/ ) and others for their help.
|
48
|
+
|
49
|
+
Thomas is writing the easy to use https://github.com/thomasfl/open-uri-and-write based on net_dav.
|
data/Rakefile
CHANGED
@@ -1,69 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "net_dav"
|
8
|
-
gem.summary = %Q{WebDAV client library in the style of Net::HTTP}
|
9
|
-
gem.description = %Q{WebDAV client library in the style of Net::HTTP, using Net::HTTP and libcurl, if installed}
|
10
|
-
gem.email = "c1.github@niftybox.net"
|
11
|
-
gem.homepage = "http://github.com/devrandom/net_dav"
|
12
|
-
gem.authors = ["Miron Cuperman","Thomas Flemming"]
|
13
|
-
gem.executables = ["dav"]
|
14
|
-
gem.add_dependency "nokogiri", ">= 1.3.0"
|
15
|
-
gem.add_development_dependency "rspec", ">= 1.2.0"
|
16
|
-
gem.add_development_dependency "webrick-webdav", ">= 1.0"
|
17
|
-
|
18
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
-
end
|
20
|
-
Jeweler::GemcutterTasks.new
|
21
|
-
rescue LoadError
|
22
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'spec/rake/spectask'
|
26
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
-
spec.libs << 'lib' << 'spec'
|
28
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
-
end
|
30
|
-
|
31
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
32
|
-
spec.libs << 'lib' << 'spec'
|
33
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
-
spec.rcov = true
|
35
|
-
end
|
36
|
-
|
37
|
-
task :spec => :check_dependencies
|
38
|
-
|
1
|
+
require "bundler/gem_tasks"
|
39
2
|
task :default => :spec
|
40
|
-
|
41
|
-
desc "release with no version change"
|
42
|
-
task :dist => [:clean, :release]
|
43
|
-
|
44
|
-
namespace :dist do
|
45
|
-
desc "release patch"
|
46
|
-
task :patch => [:clean, "version:bump:patch", :release]
|
47
|
-
desc "release with minor version bump"
|
48
|
-
task :minor => [:clean, "version:bump:minor", :release]
|
49
|
-
end
|
50
|
-
|
51
|
-
desc "build gem into pkg directory"
|
52
|
-
task :gem => [:build]
|
53
|
-
|
54
|
-
task :clean do
|
55
|
-
Dir.glob("**/*~").each do |file|
|
56
|
-
File.unlink file
|
57
|
-
end
|
58
|
-
puts "cleaned"
|
59
|
-
end
|
60
|
-
|
61
|
-
require 'rake/rdoctask'
|
62
|
-
Rake::RDocTask.new do |rdoc|
|
63
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
64
|
-
|
65
|
-
rdoc.rdoc_dir = 'rdoc'
|
66
|
-
rdoc.title = "net_dav #{version}"
|
67
|
-
rdoc.rdoc_files.include('README*')
|
68
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
69
|
-
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "net_dav"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/net/dav.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'net/https'
|
2
2
|
require 'uri'
|
3
3
|
require 'nokogiri'
|
4
|
-
require
|
4
|
+
require File.dirname(__FILE__) + "/dav/item"
|
5
5
|
require 'base64'
|
6
6
|
require 'digest/md5'
|
7
|
+
require File.dirname(__FILE__) + "/dav/version"
|
8
|
+
|
7
9
|
begin
|
8
10
|
require 'curb'
|
9
11
|
rescue LoadError
|
@@ -13,10 +15,17 @@ module Net #:nodoc:
|
|
13
15
|
# Implement a WebDAV client
|
14
16
|
class DAV
|
15
17
|
MAX_REDIRECTS = 10
|
18
|
+
|
19
|
+
def last_status
|
20
|
+
@handler.last_status
|
21
|
+
end
|
22
|
+
|
16
23
|
class NetHttpHandler
|
17
24
|
attr_writer :user, :pass
|
18
25
|
|
19
26
|
attr_accessor :disable_basic_auth
|
27
|
+
attr_reader :last_status
|
28
|
+
|
20
29
|
|
21
30
|
def verify_callback=(callback)
|
22
31
|
@http.verify_callback = callback
|
@@ -62,6 +71,8 @@ module Net #:nodoc:
|
|
62
71
|
end
|
63
72
|
|
64
73
|
def request_sending_stream(verb, path, stream, length, headers)
|
74
|
+
headers ||= {}
|
75
|
+
headers = {"User-Agent" => "Ruby"}.merge(headers)
|
65
76
|
req =
|
66
77
|
case verb
|
67
78
|
when :put
|
@@ -72,12 +83,14 @@ module Net #:nodoc:
|
|
72
83
|
req.body_stream = stream
|
73
84
|
req.content_length = length
|
74
85
|
headers.each_pair { |key, value| req[key] = value } if headers
|
75
|
-
req.content_type = '
|
86
|
+
req.content_type = 'application/octet-stream'
|
76
87
|
res = handle_request(req, headers)
|
77
88
|
res
|
78
89
|
end
|
79
90
|
|
80
91
|
def request_sending_body(verb, path, body, headers)
|
92
|
+
headers ||= {}
|
93
|
+
headers = {"User-Agent" => "Ruby"}.merge(headers)
|
81
94
|
req =
|
82
95
|
case verb
|
83
96
|
when :put
|
@@ -87,12 +100,14 @@ module Net #:nodoc:
|
|
87
100
|
end
|
88
101
|
req.body = body
|
89
102
|
headers.each_pair { |key, value| req[key] = value } if headers
|
90
|
-
req.content_type = '
|
103
|
+
req.content_type = 'application/octet-stream'
|
91
104
|
res = handle_request(req, headers)
|
92
105
|
res
|
93
106
|
end
|
94
107
|
|
95
108
|
def request_returning_body(verb, path, headers, &block)
|
109
|
+
headers ||= {}
|
110
|
+
headers = {"User-Agent" => "Ruby"}.merge(headers)
|
96
111
|
req =
|
97
112
|
case verb
|
98
113
|
when :get
|
@@ -106,6 +121,8 @@ module Net #:nodoc:
|
|
106
121
|
end
|
107
122
|
|
108
123
|
def request(verb, path, body, headers)
|
124
|
+
headers ||= {}
|
125
|
+
headers = {"User-Agent" => "Ruby"}.merge(headers)
|
109
126
|
req =
|
110
127
|
case verb
|
111
128
|
when :propfind
|
@@ -120,6 +137,10 @@ module Net #:nodoc:
|
|
120
137
|
Net::HTTP::Copy.new(path)
|
121
138
|
when :proppatch
|
122
139
|
Net::HTTP::Proppatch.new(path)
|
140
|
+
when :lock
|
141
|
+
Net::HTTP::Lock.new(path)
|
142
|
+
when :unlock
|
143
|
+
Net::HTTP::Unlock.new(path)
|
123
144
|
else
|
124
145
|
raise "unkown verb #{verb}"
|
125
146
|
end
|
@@ -134,6 +155,13 @@ module Net #:nodoc:
|
|
134
155
|
# You should choose better exception.
|
135
156
|
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
136
157
|
|
158
|
+
case @authorization
|
159
|
+
when :basic
|
160
|
+
req.basic_auth @user, @pass
|
161
|
+
when :digest
|
162
|
+
digest_auth(req, @user, @pass, response)
|
163
|
+
end
|
164
|
+
|
137
165
|
response = nil
|
138
166
|
if block
|
139
167
|
@http.request(req) {|res|
|
@@ -144,6 +172,8 @@ module Net #:nodoc:
|
|
144
172
|
else
|
145
173
|
response = @http.request(req)
|
146
174
|
end
|
175
|
+
|
176
|
+
@last_status = response.code.to_i
|
147
177
|
case response
|
148
178
|
when Net::HTTPSuccess then
|
149
179
|
return response
|
@@ -151,15 +181,15 @@ module Net #:nodoc:
|
|
151
181
|
response.error! unless @user
|
152
182
|
response.error! if req['authorization']
|
153
183
|
new_req = clone_req(req.path, req, headers)
|
154
|
-
if response['www-authenticate'] =~ /^
|
184
|
+
if response['www-authenticate'] =~ /^basic/i
|
155
185
|
if disable_basic_auth
|
156
186
|
raise "server requested basic auth, but that is disabled"
|
157
187
|
end
|
158
|
-
|
188
|
+
@authorization = :basic
|
159
189
|
else
|
160
|
-
|
190
|
+
@authorization = :digest
|
161
191
|
end
|
162
|
-
return handle_request(
|
192
|
+
return handle_request(req, headers, limit - 1, &block)
|
163
193
|
when Net::HTTPRedirection then
|
164
194
|
location = URI.parse(response['location'])
|
165
195
|
if (@uri.scheme != location.scheme ||
|
@@ -177,8 +207,13 @@ module Net #:nodoc:
|
|
177
207
|
def clone_req(path, req, headers)
|
178
208
|
new_req = req.class.new(path)
|
179
209
|
new_req.body = req.body if req.body
|
180
|
-
|
210
|
+
if (req.body_stream)
|
211
|
+
req.body_stream.rewind
|
212
|
+
new_req.body_stream = req.body_stream
|
213
|
+
end
|
214
|
+
new_req.content_length = req.content_length if req.content_length
|
181
215
|
headers.each_pair { |key, value| new_req[key] = value } if headers
|
216
|
+
new_req.content_type = req.content_type if req.content_type
|
182
217
|
return new_req
|
183
218
|
end
|
184
219
|
|
@@ -218,6 +253,27 @@ module Net #:nodoc:
|
|
218
253
|
header = header.join(', ')
|
219
254
|
request['Authorization'] = header
|
220
255
|
end
|
256
|
+
|
257
|
+
def cert_file(cert_file)
|
258
|
+
# expects a OpenSSL::X509::Certificate object as client certificate
|
259
|
+
@http.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
|
260
|
+
#puts @http.cert.not_after
|
261
|
+
#puts @http.cert.subject
|
262
|
+
end
|
263
|
+
|
264
|
+
def cert_key(cert_file, cert_file_password)
|
265
|
+
# expects a OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object
|
266
|
+
if cert_file_password then
|
267
|
+
@http.key = OpenSSL::PKey::RSA.new(File.read(cert_file),cert_file_password)
|
268
|
+
else
|
269
|
+
@http.key = OpenSSL::PKey::RSA.new(File.read(cert_file))
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
# path of a CA certification file in PEM format. The file can contain several CA certificates.
|
274
|
+
def ca_file(ca_file)
|
275
|
+
@http.ca_file = ca_file
|
276
|
+
end
|
221
277
|
end
|
222
278
|
|
223
279
|
|
@@ -267,6 +323,9 @@ module Net #:nodoc:
|
|
267
323
|
end
|
268
324
|
end
|
269
325
|
curl.perform
|
326
|
+
|
327
|
+
@last_status = curl.response_code
|
328
|
+
|
270
329
|
unless curl.response_code >= 200 && curl.response_code < 300
|
271
330
|
header_block = curl.header_str.split(/\r?\n\r?\n/)[-1]
|
272
331
|
msg = header_block.split(/\r?\n/)[0]
|
@@ -275,6 +334,23 @@ module Net #:nodoc:
|
|
275
334
|
end
|
276
335
|
curl.body_str
|
277
336
|
end
|
337
|
+
|
338
|
+
def cert_file(cert_file)
|
339
|
+
# expects a cert file
|
340
|
+
@curl.cert = cert_file
|
341
|
+
end
|
342
|
+
|
343
|
+
def cert_key(cert_file, cert_file_password)
|
344
|
+
if cert_file_password then
|
345
|
+
@curl.certpassword = cert_file_password
|
346
|
+
end
|
347
|
+
@curl.key = cert_key
|
348
|
+
end
|
349
|
+
|
350
|
+
def ca_file(ca_file)
|
351
|
+
# path of a cacert bundle for this instance. This file will be used to validate SSL certificates.
|
352
|
+
@curl.cacert = ca_file
|
353
|
+
end
|
278
354
|
|
279
355
|
end
|
280
356
|
|
@@ -332,6 +408,8 @@ module Net #:nodoc:
|
|
332
408
|
# You can pass :curl => false if you want to disable use
|
333
409
|
# of the curb (libcurl) gem if present for acceleration
|
334
410
|
def initialize(uri, options = nil)
|
411
|
+
@last_status = 0
|
412
|
+
|
335
413
|
@have_curl = Curl rescue nil
|
336
414
|
if options && options.has_key?(:curl) && !options[:curl]
|
337
415
|
@have_curl = false
|
@@ -339,6 +417,7 @@ module Net #:nodoc:
|
|
339
417
|
@uri = uri
|
340
418
|
@uri = URI.parse(@uri) if @uri.is_a? String
|
341
419
|
@handler = @have_curl ? CurlHandler.new(@uri) : NetHttpHandler.new(@uri)
|
420
|
+
@headers = options && options[:headers] ? options[:headers] : {}
|
342
421
|
end
|
343
422
|
|
344
423
|
# Opens the connection to the host. Yields self to the block.
|
@@ -360,8 +439,33 @@ module Net #:nodoc:
|
|
360
439
|
def credentials(user, pass)
|
361
440
|
@handler.user = user
|
362
441
|
@handler.pass = pass
|
442
|
+
|
443
|
+
# Return something explicitly since this command might be run in a
|
444
|
+
# console where the last statement would be printed.
|
445
|
+
nil
|
446
|
+
end
|
447
|
+
|
448
|
+
# Set credentials for ssl certificate authentication
|
449
|
+
def ssl_certificate(cert_file, *cert_file_password)
|
450
|
+
@handler.cert_file(cert_file)
|
451
|
+
@handler.cert_key(cert_file, cert_file_password)
|
452
|
+
|
453
|
+
# Return something explicitly since this command might be run in a
|
454
|
+
# console where the last statement would be printed.
|
455
|
+
nil
|
456
|
+
end
|
457
|
+
|
458
|
+
# Set additional ssl authorities for ssl certificate authentication
|
459
|
+
def ssl_authority(ca_file)
|
460
|
+
@handler.ca_file(ca_file)
|
461
|
+
nil
|
363
462
|
end
|
364
463
|
|
464
|
+
# Set extra headers for the dav request
|
465
|
+
def headers(headers)
|
466
|
+
@headers = headers
|
467
|
+
end
|
468
|
+
|
365
469
|
# Perform a PROPFIND request
|
366
470
|
#
|
367
471
|
# Example:
|
@@ -391,7 +495,7 @@ module Net #:nodoc:
|
|
391
495
|
if(!body)
|
392
496
|
body = '<?xml version="1.0" encoding="utf-8"?><DAV:propfind xmlns:DAV="DAV:"><DAV:allprop/></DAV:propfind>'
|
393
497
|
end
|
394
|
-
res = @handler.request(:propfind, path, body, headers)
|
498
|
+
res = @handler.request(:propfind, path, body, headers.merge(@headers))
|
395
499
|
Nokogiri::XML.parse(res.body)
|
396
500
|
end
|
397
501
|
|
@@ -440,7 +544,7 @@ module Net #:nodoc:
|
|
440
544
|
uri = @uri.merge(item.xpath("x:href", namespaces).inner_text)
|
441
545
|
size = item.%(".//x:getcontentlength", namespaces).inner_text rescue nil
|
442
546
|
type = item.%(".//x:collection", namespaces) ? :directory : :file
|
443
|
-
res = Item.new(self, uri, type, size)
|
547
|
+
res = Item.new(self, uri, type, size, item)
|
444
548
|
if type == :file then
|
445
549
|
|
446
550
|
if(options[:filename])then
|
@@ -493,7 +597,7 @@ module Net #:nodoc:
|
|
493
597
|
|
494
598
|
def get(path, &block)
|
495
599
|
path = @uri.merge(path).path
|
496
|
-
body = @handler.request_returning_body(:get, path,
|
600
|
+
body = @handler.request_returning_body(:get, path, @headers, &block)
|
497
601
|
body
|
498
602
|
end
|
499
603
|
|
@@ -505,7 +609,7 @@ module Net #:nodoc:
|
|
505
609
|
# end
|
506
610
|
def put(path, stream, length)
|
507
611
|
path = @uri.merge(path).path
|
508
|
-
res = @handler.request_sending_stream(:put, path, stream, length,
|
612
|
+
res = @handler.request_sending_stream(:put, path, stream, length, @headers)
|
509
613
|
res.body
|
510
614
|
end
|
511
615
|
|
@@ -516,7 +620,7 @@ module Net #:nodoc:
|
|
516
620
|
#
|
517
621
|
def put_string(path, str)
|
518
622
|
path = @uri.merge(path).path
|
519
|
-
res = @handler.request_sending_body(:put, path, str,
|
623
|
+
res = @handler.request_sending_body(:put, path, str, @headers)
|
520
624
|
res.body
|
521
625
|
end
|
522
626
|
|
@@ -526,7 +630,7 @@ module Net #:nodoc:
|
|
526
630
|
# dav.delete(uri.path)
|
527
631
|
def delete(path)
|
528
632
|
path = @uri.merge(path).path
|
529
|
-
res = @handler.request(:delete, path, nil,
|
633
|
+
res = @handler.request(:delete, path, nil, @headers)
|
530
634
|
res.body
|
531
635
|
end
|
532
636
|
|
@@ -538,7 +642,7 @@ module Net #:nodoc:
|
|
538
642
|
path = @uri.merge(path).path
|
539
643
|
destination = @uri.merge(destination).to_s
|
540
644
|
headers = {'Destination' => destination}
|
541
|
-
res = @handler.request(:move, path, nil, headers)
|
645
|
+
res = @handler.request(:move, path, nil, headers.merge(@headers))
|
542
646
|
res.body
|
543
647
|
end
|
544
648
|
|
@@ -550,7 +654,7 @@ module Net #:nodoc:
|
|
550
654
|
path = @uri.merge(path).path
|
551
655
|
destination = @uri.merge(destination).to_s
|
552
656
|
headers = {'Destination' => destination}
|
553
|
-
res = @handler.request(:copy, path, nil, headers)
|
657
|
+
res = @handler.request(:copy, path, nil, headers.merge(@headers))
|
554
658
|
res.body
|
555
659
|
end
|
556
660
|
|
@@ -558,22 +662,49 @@ module Net #:nodoc:
|
|
558
662
|
# update properties on resources or collections.
|
559
663
|
#
|
560
664
|
# Example:
|
561
|
-
# dav.proppatch(uri.path,
|
665
|
+
# dav.proppatch(uri.path,
|
666
|
+
# "<d:set><d:prop>" +
|
667
|
+
# "<d:creationdate>#{new_date}</d:creationdate>" +
|
668
|
+
# "</d:set></d:prop>" +
|
669
|
+
# )
|
562
670
|
def proppatch(path, xml_snippet)
|
563
671
|
path = @uri.merge(path).path
|
564
672
|
headers = {'Depth' => '1'}
|
565
673
|
body = '<?xml version="1.0"?>' +
|
566
674
|
'<d:propertyupdate xmlns:d="DAV:">' +
|
567
|
-
|
568
|
-
'<d:prop>' +
|
569
|
-
xml_snippet +
|
570
|
-
'</d:prop>' +
|
571
|
-
'</d:set>' +
|
675
|
+
xml_snippet +
|
572
676
|
'</d:propertyupdate>'
|
573
|
-
res = @handler.request(:proppatch, path, body, headers)
|
677
|
+
res = @handler.request(:proppatch, path, body, headers.merge(@headers))
|
574
678
|
Nokogiri::XML.parse(res.body)
|
575
679
|
end
|
576
680
|
|
681
|
+
# Send a lock request to the server
|
682
|
+
#
|
683
|
+
# On success returns an XML response body with a Lock-Token
|
684
|
+
#
|
685
|
+
# Example:
|
686
|
+
# dav.lock(uri.path, "<d:lockscope><d:exclusive/></d:lockscope><d:locktype><d:write/></d:locktype><d:owner>Owner</d:owner>")
|
687
|
+
def lock(path, xml_snippet)
|
688
|
+
path = @uri.merge(path).path
|
689
|
+
headers = {'Depth' => '1'}
|
690
|
+
body = '<?xml version="1.0"?>' +
|
691
|
+
'<d:lockinfo xmlns:d="DAV:">' +
|
692
|
+
xml_snippet +
|
693
|
+
'</d:lockinfo>'
|
694
|
+
res = @handler.request(:lock, path, body, headers.merge(@headers))
|
695
|
+
Nokogiri::XML.parse(res.body)
|
696
|
+
end
|
697
|
+
|
698
|
+
# Send an unlock request to the server
|
699
|
+
#
|
700
|
+
# Example:
|
701
|
+
# dav.unlock(uri.path, "opaquelocktoken:eee47ade-09ac-626b-02f7-e354175d984e")
|
702
|
+
def unlock(path, locktoken)
|
703
|
+
headers = {'Lock-Token' => '<'+locktoken+'>'}
|
704
|
+
path = @uri.merge(path).path
|
705
|
+
res = @handler.request(:unlock, path, nil, headers.merge(@headers))
|
706
|
+
end
|
707
|
+
|
577
708
|
# Returns true if resource exists on server.
|
578
709
|
#
|
579
710
|
# Example:
|
@@ -584,7 +715,7 @@ module Net #:nodoc:
|
|
584
715
|
headers = {'Depth' => '1'}
|
585
716
|
body = '<?xml version="1.0" encoding="utf-8"?><DAV:propfind xmlns:DAV="DAV:"><DAV:allprop/></DAV:propfind>'
|
586
717
|
begin
|
587
|
-
res = @handler.request(:propfind, path, body, headers)
|
718
|
+
res = @handler.request(:propfind, path, body, headers.merge(@headers))
|
588
719
|
rescue
|
589
720
|
return false
|
590
721
|
end
|
@@ -594,7 +725,7 @@ module Net #:nodoc:
|
|
594
725
|
# Makes a new directory (collection)
|
595
726
|
def mkdir(path)
|
596
727
|
path = @uri.merge(path).path
|
597
|
-
res = @handler.request(:mkcol, path, nil,
|
728
|
+
res = @handler.request(:mkcol, path, nil, @headers)
|
598
729
|
res.body
|
599
730
|
end
|
600
731
|
|
data/lib/net/dav/item.rb
CHANGED
@@ -2,6 +2,40 @@ module Net
|
|
2
2
|
class DAV
|
3
3
|
# Hold items found using Net::DAV#find
|
4
4
|
class Item
|
5
|
+
|
6
|
+
# Hold <response> XML element and provides facilities to query attributes
|
7
|
+
class Props
|
8
|
+
|
9
|
+
# The <response> XML element
|
10
|
+
attr_reader :response
|
11
|
+
|
12
|
+
def initialize(response)
|
13
|
+
@response = response
|
14
|
+
@namespaces = {"x" => "DAV:"}
|
15
|
+
end
|
16
|
+
|
17
|
+
def displayname
|
18
|
+
@response./(".//x:displayname", @namespaces).inner_text
|
19
|
+
end
|
20
|
+
|
21
|
+
def contenttype
|
22
|
+
@response./(".//x:getcontenttype", @namespaces).inner_text rescue nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def contentlength
|
26
|
+
@response./(".//x:getcontentlength", @namespaces).inner_text rescue nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def creationdate
|
30
|
+
Time.parse(@response./(".//x:creationdate", @namespaces).inner_text)
|
31
|
+
end
|
32
|
+
|
33
|
+
def lastmodificationdate
|
34
|
+
Time.parse(@response./(".//x:getlastmodified", @namespaces).inner_text)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
5
39
|
# URI of item
|
6
40
|
attr_reader :uri
|
7
41
|
|
@@ -11,16 +45,20 @@ module Net
|
|
11
45
|
# Type of item - :directory or :file
|
12
46
|
attr_reader :type
|
13
47
|
|
48
|
+
# Properties holder
|
49
|
+
attr_reader :properties
|
50
|
+
|
14
51
|
# Synonym for uri
|
15
52
|
def url
|
16
53
|
@uri
|
17
54
|
end
|
18
55
|
|
19
|
-
def initialize(dav, uri, type, size) #:nodoc:
|
56
|
+
def initialize(dav, uri, type, size, properties) #:nodoc:
|
20
57
|
@uri = uri
|
21
58
|
@size = size.to_i rescue nil
|
22
59
|
@type = type
|
23
60
|
@dav = dav
|
61
|
+
@properties = Props.new(properties)
|
24
62
|
end
|
25
63
|
|
26
64
|
# Get content from server if needed and return as string
|
data/net_dav.gemspec
CHANGED
@@ -1,71 +1,38 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'net/dav/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "net_dav"
|
8
|
+
spec.version = Net::DAV::VERSION
|
9
|
+
spec.authors = ["Miron Cuperman", "Thomas Flemming"]
|
10
|
+
spec.email = ["c1.github@niftybox.net"]
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
s.default_executable = %q{dav}
|
14
|
-
s.description = %q{WebDAV client library in the style of Net::HTTP, using Net::HTTP and libcurl, if installed}
|
15
|
-
s.email = %q{c1.github@niftybox.net}
|
16
|
-
s.executables = ["dav"]
|
17
|
-
s.extra_rdoc_files = [
|
18
|
-
"LICENSE",
|
19
|
-
"README.rdoc"
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".document",
|
23
|
-
".gitignore",
|
24
|
-
"LICENSE",
|
25
|
-
"README.rdoc",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"bin/dav",
|
29
|
-
"lib/net/dav.rb",
|
30
|
-
"lib/net/dav/item.rb",
|
31
|
-
"net_dav.gemspec",
|
32
|
-
"net_dav.gif",
|
33
|
-
"script/multi-test",
|
34
|
-
"spec/fixtures/file.html",
|
35
|
-
"spec/integration/net_dav_spec.rb",
|
36
|
-
"spec/integration/webdav_server.rb",
|
37
|
-
"spec/spec.opts",
|
38
|
-
"spec/spec_helper.rb",
|
39
|
-
"tmp/.gitignore"
|
40
|
-
]
|
41
|
-
s.homepage = %q{http://github.com/devrandom/net_dav}
|
42
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
-
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.3.5}
|
45
|
-
s.summary = %q{WebDAV client library in the style of Net::HTTP}
|
46
|
-
s.test_files = [
|
47
|
-
"spec/spec_helper.rb",
|
48
|
-
"spec/integration/webdav_server.rb",
|
49
|
-
"spec/integration/net_dav_spec.rb"
|
50
|
-
]
|
12
|
+
spec.summary = "WebDAV client library in the style of Net::HTTP, using Net::HTTP and libcurl, if installed"
|
13
|
+
spec.description = "WebDAV client library in the style of Net::HTTP, using Net::HTTP and libcurl, if installed"
|
14
|
+
spec.homepage = "https://github.com/devrandom/net_dav"
|
51
15
|
|
52
|
-
|
53
|
-
|
54
|
-
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
55
23
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
s.add_dependency(%q<rspec>, [">= 1.2.0"])
|
68
|
-
s.add_dependency(%q<webrick-webdav>, [">= 1.0"])
|
69
|
-
end
|
70
|
-
end
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "webrick-webdav"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
|
34
|
+
spec.add_dependency "nokogiri"
|
71
35
|
|
36
|
+
|
37
|
+
|
38
|
+
end
|
metadata
CHANGED
@@ -1,105 +1,134 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: net_dav
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Miron Cuperman
|
8
8
|
- Thomas Flemming
|
9
9
|
autorequire:
|
10
|
-
bindir:
|
10
|
+
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2016-08-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.12'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.12'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: webrick-webdav
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
22
46
|
- - ">="
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
25
|
-
version:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: rspec
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
28
49
|
type: :development
|
29
|
-
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
32
53
|
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
35
|
-
|
36
|
-
|
37
|
-
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
38
63
|
type: :development
|
39
|
-
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
requirements:
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: nokogiri
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
42
74
|
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version:
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
-
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: WebDAV client library in the style of Net::HTTP, using Net::HTTP and
|
85
|
+
libcurl, if installed
|
86
|
+
email:
|
87
|
+
- c1.github@niftybox.net
|
88
|
+
executables: []
|
50
89
|
extensions: []
|
51
|
-
|
52
|
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
|
56
|
-
- .
|
57
|
-
-
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".document"
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- Gemfile
|
58
97
|
- LICENSE
|
59
98
|
- README.rdoc
|
60
99
|
- Rakefile
|
61
|
-
-
|
100
|
+
- bin/console
|
62
101
|
- bin/dav
|
102
|
+
- bin/setup
|
63
103
|
- lib/net/dav.rb
|
64
104
|
- lib/net/dav/item.rb
|
105
|
+
- lib/net/dav/version.rb
|
65
106
|
- net_dav.gemspec
|
66
107
|
- net_dav.gif
|
67
108
|
- script/multi-test
|
68
|
-
- spec/fixtures/file.html
|
69
|
-
- spec/integration/net_dav_spec.rb
|
70
|
-
- spec/integration/webdav_server.rb
|
71
|
-
- spec/spec.opts
|
72
|
-
- spec/spec_helper.rb
|
73
109
|
- tmp/.gitignore
|
74
|
-
|
75
|
-
homepage: http://github.com/devrandom/net_dav
|
110
|
+
homepage: https://github.com/devrandom/net_dav
|
76
111
|
licenses: []
|
77
|
-
|
112
|
+
metadata: {}
|
78
113
|
post_install_message:
|
79
|
-
rdoc_options:
|
80
|
-
|
81
|
-
require_paths:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
82
116
|
- lib
|
83
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
85
119
|
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
88
|
-
|
89
|
-
|
90
|
-
requirements:
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
91
124
|
- - ">="
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version:
|
94
|
-
version:
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
95
127
|
requirements: []
|
96
|
-
|
97
128
|
rubyforge_project:
|
98
|
-
rubygems_version:
|
129
|
+
rubygems_version: 2.2.2
|
99
130
|
signing_key:
|
100
|
-
specification_version:
|
101
|
-
summary: WebDAV client library in the style of Net::HTTP
|
102
|
-
|
103
|
-
|
104
|
-
- spec/integration/webdav_server.rb
|
105
|
-
- spec/integration/net_dav_spec.rb
|
131
|
+
specification_version: 4
|
132
|
+
summary: WebDAV client library in the style of Net::HTTP, using Net::HTTP and libcurl,
|
133
|
+
if installed
|
134
|
+
test_files: []
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.5.0
|
data/spec/fixtures/file.html
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Content
|
@@ -1,124 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/webdav_server')
|
3
|
-
|
4
|
-
describe "Net::Dav" do
|
5
|
-
|
6
|
-
before(:all) do
|
7
|
-
# Start webdav server in subprocess
|
8
|
-
@pid = fork do
|
9
|
-
webdav_server(:port => 10080, :authentication => false)
|
10
|
-
end
|
11
|
-
# Wait for webdavserver to start
|
12
|
-
wait_for_server("http://localhost:10080/")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should create a Net::Dav object" do
|
16
|
-
Net::DAV.new("http://localhost.localdomain/").should_not be_nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should read properties from webdav server" do
|
20
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
21
|
-
@props = dav.propfind("/").to_s
|
22
|
-
@props.should match(/200 OK/)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should raise if finding non-existent path" do
|
26
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
27
|
-
lambda do
|
28
|
-
dav.find("/") do |item|
|
29
|
-
end
|
30
|
-
end.should_not raise_error
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should raise if finding non-existent path" do
|
34
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
35
|
-
lambda do
|
36
|
-
dav.find("/asdf") do |item|
|
37
|
-
end
|
38
|
-
end.should raise_error Net::HTTPServerException
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should write files to webdav server" do
|
42
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
43
|
-
@props = find_props_or_error(dav, "/new_file.html")
|
44
|
-
@props.should match(/404.*Not found/i)
|
45
|
-
|
46
|
-
dav.put_string("/new_file.html","File contents")
|
47
|
-
|
48
|
-
@props = find_props_or_error(dav, "/new_file.html")
|
49
|
-
@props.should match(/200 OK/i)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should delete files from webdav server" do
|
53
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
54
|
-
|
55
|
-
@props = find_props_or_error(dav, "/new_file.html")
|
56
|
-
@props.should match(/200 OK/i)
|
57
|
-
|
58
|
-
dav.delete("/new_file.html")
|
59
|
-
@props = find_props_or_error(dav, "/new_file.html")
|
60
|
-
@props.should match(/404.*Not found/i)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should copy files on webdav server" do
|
64
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
65
|
-
|
66
|
-
@props = find_props_or_error(dav, "/file.html")
|
67
|
-
@props.should match(/200 OK/i)
|
68
|
-
|
69
|
-
dav.copy("/file.html","/copied_file.html")
|
70
|
-
@props = find_props_or_error(dav, "/copied_file.html")
|
71
|
-
@props.should match(/200 OK/i)
|
72
|
-
|
73
|
-
dav.delete("/copied_file.html")
|
74
|
-
|
75
|
-
@props = find_props_or_error(dav, "/copied_file.html")
|
76
|
-
@props.should match(/404.*Not found/i)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should move files on webdav server" do
|
80
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
81
|
-
|
82
|
-
@props = find_props_or_error(dav, "/file.html")
|
83
|
-
@props.should match(/200 OK/i)
|
84
|
-
|
85
|
-
dav.move("/file.html","/moved_file.html")
|
86
|
-
@props = find_props_or_error(dav, "/moved_file.html")
|
87
|
-
@props.should match(/200 OK/i)
|
88
|
-
|
89
|
-
@props = find_props_or_error(dav, "/file.html")
|
90
|
-
@props.should match(/404.*Not found/i)
|
91
|
-
|
92
|
-
dav.move("/moved_file.html","/file.html")
|
93
|
-
@props = find_props_or_error(dav, "/file.html")
|
94
|
-
@props.should match(/200 OK/i)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should retrieve acl" do
|
98
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
99
|
-
@props = dav.propfind("/", :acl).to_s
|
100
|
-
@props.should match(/200 OK/i)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should detect if resource or collection exists on server" do
|
104
|
-
dav = Net::DAV.new("http://localhost:10080/")
|
105
|
-
dav.exists?('/file.html').should == true
|
106
|
-
dav.exists?('/totally_unknown_file.html').should == false
|
107
|
-
end
|
108
|
-
|
109
|
-
# proppatch seems to work, but our simple webdav server don't update properties
|
110
|
-
# it "should alter properties on resources on webdav server" do
|
111
|
-
# dav = Net::DAV.new("http://localhost:10080/")
|
112
|
-
# @props = find_props_or_error(dav, "/file.html")
|
113
|
-
# puts @props
|
114
|
-
# dav.proppatch("/file.html", "<d:resourcetype>static-file</d:resourcetype>")
|
115
|
-
# @props = find_props_or_error(dav, "/file.html")
|
116
|
-
# puts @props
|
117
|
-
# end
|
118
|
-
|
119
|
-
after(:all) do
|
120
|
-
# Shut down webdav server
|
121
|
-
Process.kill('SIGKILL', @pid) rescue nil
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'webrick'
|
5
|
-
require 'webrick/httpservlet/webdavhandler'
|
6
|
-
|
7
|
-
# Web server with WebDAV extensions
|
8
|
-
#
|
9
|
-
# Usage: ruby webdav_server.rb
|
10
|
-
|
11
|
-
# Code based on:
|
12
|
-
# http://github.com/aslakhellesoy/webdavjs/blob/master/spec/webdav_server.rb
|
13
|
-
|
14
|
-
|
15
|
-
# Monkey patch REXML to always nil-indent. The indentation is broken in REXML
|
16
|
-
# on Ruby 1.8.6 and even when fixed it confuses OS-X.
|
17
|
-
module REXML
|
18
|
-
module Node
|
19
|
-
alias old_to_s to_s
|
20
|
-
def to_s(indent=nil)
|
21
|
-
old_to_s(nil)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/223386
|
27
|
-
# http://gmarrone.objectblues.net/cgi-bin/wiki/WebDAV_-_Linux_server%2c_Mac_OS_X_client
|
28
|
-
module WEBrick
|
29
|
-
module HTTPServlet
|
30
|
-
class WebDAVHandlerVersion2 < WebDAVHandler
|
31
|
-
|
32
|
-
def do_OPTIONS(req, res)
|
33
|
-
super
|
34
|
-
res["DAV"] = "1,2"
|
35
|
-
end
|
36
|
-
|
37
|
-
def do_LOCK(req, res)
|
38
|
-
res.body << "<XXX-#{Time.now.to_s}/>"
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
class WebDAVHandlerVersion3 < WebDAVHandlerVersion2
|
44
|
-
|
45
|
-
# Enable authentication
|
46
|
-
$REALM = "WebDav share"
|
47
|
-
$USER = "myuser"
|
48
|
-
$PASS = "mypass"
|
49
|
-
|
50
|
-
def service(req, res)
|
51
|
-
HTTPAuth.basic_auth(req, res, $REALM) {|user, pass|
|
52
|
-
# this block returns true if
|
53
|
-
# authentication token is valid
|
54
|
-
user == $USER && pass == $PASS
|
55
|
-
}
|
56
|
-
super
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def webdav_server(*options)
|
65
|
-
port = 10080
|
66
|
-
if(options and options[0][:port])
|
67
|
-
port = options[0][:port]
|
68
|
-
end
|
69
|
-
log = WEBrick::Log.new
|
70
|
-
log.level = WEBrick::Log::DEBUG if $DEBUG
|
71
|
-
serv = WEBrick::HTTPServer.new({:Port => port, :Logger => log})
|
72
|
-
|
73
|
-
dir = File.expand_path(File.dirname(__FILE__)) + '/../fixtures'
|
74
|
-
if(options and options[0][:authentication])
|
75
|
-
serv.mount("/", WEBrick::HTTPServlet::WebDAVHandlerVersion3, dir)
|
76
|
-
else
|
77
|
-
serv.mount("/", WEBrick::HTTPServlet::WebDAVHandlerVersion2, dir)
|
78
|
-
end
|
79
|
-
|
80
|
-
trap(:INT){ serv.shutdown }
|
81
|
-
serv.start
|
82
|
-
end
|
83
|
-
|
84
|
-
if($0 == __FILE__)
|
85
|
-
|
86
|
-
webdav_server(:port => 10080,:authentication => false)
|
87
|
-
end
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/spec/spec_helper.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'rubygems'
|
4
|
-
require 'net/dav'
|
5
|
-
require 'spec'
|
6
|
-
require 'spec/autorun'
|
7
|
-
|
8
|
-
Spec::Runner.configure do |config|
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
# Wait for webdav server to start up
|
13
|
-
def wait_for_server(address)
|
14
|
-
server_running = false
|
15
|
-
dav = Net::DAV.new(address)
|
16
|
-
count = 0
|
17
|
-
while(not(server_running))
|
18
|
-
begin
|
19
|
-
sleep(0.1)
|
20
|
-
props = dav.propfind("/").to_s
|
21
|
-
if(props.match(/200 OK/))
|
22
|
-
server_running = true
|
23
|
-
else
|
24
|
-
warn "Webdav server should return \"200 OK\" "
|
25
|
-
exit(1)
|
26
|
-
end
|
27
|
-
rescue
|
28
|
-
count += 1
|
29
|
-
puts "Server not running. Retrying..." if ((count % 10) == 0)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
dav = nil
|
33
|
-
end
|
34
|
-
|
35
|
-
# Profind helper. Returns properties or error
|
36
|
-
def find_props_or_error(dav, path)
|
37
|
-
begin
|
38
|
-
return dav.propfind(path).to_s
|
39
|
-
rescue Net::HTTPServerException => e
|
40
|
-
return e.to_s
|
41
|
-
end
|
42
|
-
end
|