dav4rack 0.2.4 → 0.2.5
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 +2 -0
- data/lib/dav4rack/controller.rb +4 -7
- data/lib/dav4rack/file.rb +1 -1
- data/lib/dav4rack/file_resource.rb +1 -1
- data/lib/dav4rack/logger.rb +7 -3
- data/lib/dav4rack/resource.rb +6 -1
- data/lib/dav4rack/version.rb +15 -1
- data/spec/handler_spec.rb +25 -47
- metadata +28 -2
data/README.rdoc
CHANGED
@@ -306,6 +306,8 @@ A big thanks to everyone contributing to help make this project better.
|
|
306
306
|
* {antiloopgmbh}[http://github.com/antiloopgmbh]
|
307
307
|
* {krug}[http://github.com/krug]
|
308
308
|
* {teefax}[http://github.com/teefax]
|
309
|
+
* {buffym}[https://github.com/buffym]
|
310
|
+
* {jbangert}[https://github.com/jbangert]
|
309
311
|
|
310
312
|
== License
|
311
313
|
|
data/lib/dav4rack/controller.rb
CHANGED
@@ -37,7 +37,7 @@ module DAV4Rack
|
|
37
37
|
# Return response to OPTIONS
|
38
38
|
def options
|
39
39
|
response["Allow"] = 'OPTIONS,HEAD,GET,PUT,POST,DELETE,PROPFIND,PROPPATCH,MKCOL,COPY,MOVE,LOCK,UNLOCK'
|
40
|
-
response["Dav"] = "2"
|
40
|
+
response["Dav"] = "1, 2"
|
41
41
|
response["Ms-Author-Via"] = "DAV"
|
42
42
|
OK
|
43
43
|
end
|
@@ -67,14 +67,11 @@ module DAV4Rack
|
|
67
67
|
# Return response to PUT
|
68
68
|
def put
|
69
69
|
raise Forbidden if resource.collection?
|
70
|
+
raise Conflict unless resource.parent_exists? && resource.parent.collection?
|
70
71
|
resource.lock_check
|
71
72
|
status = resource.put(request, response)
|
72
|
-
|
73
|
-
|
74
|
-
xml.href "#{scheme}://#{host}:#{port}#{url_escape(resource.public_path)}"
|
75
|
-
xml.status "#{http_version} #{status.status_line}"
|
76
|
-
end
|
77
|
-
end
|
73
|
+
response['Content-Location'] = "#{scheme}://#{host}:#{port}#{resource.public_path}" if status == Created
|
74
|
+
status
|
78
75
|
end
|
79
76
|
|
80
77
|
# Return response to POST
|
data/lib/dav4rack/file.rb
CHANGED
@@ -27,7 +27,7 @@ module DAV4Rack
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def not_found
|
30
|
-
body = "File not found: #{Utils.unescape(env["PATH_INFO"])}\n"
|
30
|
+
body = "File not found: #{Rack::Utils.unescape(env["PATH_INFO"])}\n"
|
31
31
|
[404, {"Content-Type" => "text/plain",
|
32
32
|
"Content-Length" => body.size.to_s,
|
33
33
|
"X-Cascade" => "pass"},
|
data/lib/dav4rack/logger.rb
CHANGED
@@ -5,10 +5,14 @@ module DAV4Rack
|
|
5
5
|
# to log messages from the library.
|
6
6
|
class Logger
|
7
7
|
class << self
|
8
|
-
# args:: Arguments for Logger -> [path, level] (level is optional)
|
8
|
+
# args:: Arguments for Logger -> [path, level] (level is optional) or a Logger instance
|
9
9
|
# Set the path to the log file.
|
10
10
|
def set(*args)
|
11
|
-
|
11
|
+
if(args.first.is_a?(Logger))
|
12
|
+
@@logger = args.first
|
13
|
+
else
|
14
|
+
@@logger = ::Logger.new(args.first, 'weekly')
|
15
|
+
end
|
12
16
|
if(args.size > 1)
|
13
17
|
@@logger.level = args[1]
|
14
18
|
end
|
@@ -21,4 +25,4 @@ module DAV4Rack
|
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
24
|
-
end
|
28
|
+
end
|
data/lib/dav4rack/resource.rb
CHANGED
@@ -63,7 +63,12 @@ module DAV4Rack
|
|
63
63
|
# NOTE: Customized Resources should not use initialize for setup. Instead
|
64
64
|
# use the #setup method
|
65
65
|
def initialize(public_path, path, request, response, options)
|
66
|
-
@skip_alias = [
|
66
|
+
@skip_alias = [
|
67
|
+
:authenticate, :authentication_error_msg,
|
68
|
+
:authentication_realm, :path, :options,
|
69
|
+
:public_path, :request, :response, :user,
|
70
|
+
:user=, :setup
|
71
|
+
]
|
67
72
|
@public_path = public_path.dup
|
68
73
|
@path = path.dup
|
69
74
|
@request = request
|
data/lib/dav4rack/version.rb
CHANGED
@@ -1,3 +1,17 @@
|
|
1
1
|
module DAV4Rack
|
2
|
-
|
2
|
+
class Version
|
3
|
+
|
4
|
+
attr_reader :major, :minor, :tiny
|
5
|
+
|
6
|
+
def initialize(version)
|
7
|
+
version = version.split('.')
|
8
|
+
@major, @minor, @tiny = [version[0].to_i, version[1].to_i, version[2].to_i]
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"#{@major}.#{@minor}.#{@tiny}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
VERSION = Version.new('0.2.5')
|
3
17
|
end
|
data/spec/handler_spec.rb
CHANGED
@@ -97,8 +97,7 @@ describe DAV4Rack::Handler do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'should return headers' do
|
100
|
-
put('/test.html', :input => '<html/>')
|
101
|
-
multi_status_ok.should eq true
|
100
|
+
put('/test.html', :input => '<html/>').should be_created
|
102
101
|
head('/test.html').should be_ok
|
103
102
|
|
104
103
|
response.headers['etag'].should_not be_nil
|
@@ -115,38 +114,32 @@ describe DAV4Rack::Handler do
|
|
115
114
|
end
|
116
115
|
|
117
116
|
it 'should create a resource and allow its retrieval' do
|
118
|
-
put('/test', :input => 'body')
|
119
|
-
multi_status_ok.should eq true
|
117
|
+
put('/test', :input => 'body').should be_created
|
120
118
|
get('/test').should be_ok
|
121
119
|
response.body.should == 'body'
|
122
120
|
end
|
123
|
-
|
121
|
+
|
124
122
|
it 'should return an absolute url after a put request' do
|
125
|
-
put('/test', :input => 'body')
|
126
|
-
|
127
|
-
multistatus_response('/D:href').first.text.should =~ /http:\/\/localhost(:\d+)?\/test/
|
123
|
+
put('/test', :input => 'body').should be_created
|
124
|
+
response['content-location'].should =~ /http:\/\/localhost(:\d+)?\/test/
|
128
125
|
end
|
129
126
|
|
130
127
|
it 'should create and find a url with escaped characters' do
|
131
|
-
put(url_escape('/a b'), :input => 'body')
|
132
|
-
multi_status_ok.should eq true
|
128
|
+
put(url_escape('/a b'), :input => 'body').should be_created
|
133
129
|
get(url_escape('/a b')).should be_ok
|
134
130
|
response.body.should == 'body'
|
135
131
|
end
|
136
132
|
|
137
133
|
it 'should delete a single resource' do
|
138
|
-
put('/test', :input => 'body')
|
139
|
-
multi_status_ok.should eq true
|
134
|
+
put('/test', :input => 'body').should be_created
|
140
135
|
delete('/test').should be_no_content
|
141
136
|
end
|
142
137
|
|
143
138
|
it 'should delete recursively' do
|
144
139
|
mkcol('/folder')
|
145
140
|
multi_status_created.should eq true
|
146
|
-
put('/folder/a', :input => 'body')
|
147
|
-
|
148
|
-
put('/folder/b', :input => 'body')
|
149
|
-
multi_status_ok.should eq true
|
141
|
+
put('/folder/a', :input => 'body').should be_created
|
142
|
+
put('/folder/b', :input => 'body').should be_created
|
150
143
|
|
151
144
|
delete('/folder').should be_no_content
|
152
145
|
get('/folder').should be_not_found
|
@@ -155,28 +148,24 @@ describe DAV4Rack::Handler do
|
|
155
148
|
end
|
156
149
|
|
157
150
|
it 'should not allow copy to another domain' do
|
158
|
-
put('/test', :input => 'body')
|
159
|
-
multi_status_ok.should eq true
|
151
|
+
put('/test', :input => 'body').should be_created
|
160
152
|
copy('http://localhost/', 'HTTP_DESTINATION' => 'http://another/').should be_bad_gateway
|
161
153
|
end
|
162
154
|
|
163
155
|
it 'should not allow copy to the same resource' do
|
164
|
-
put('/test', :input => 'body')
|
165
|
-
multi_status_ok.should eq true
|
156
|
+
put('/test', :input => 'body').should be_created
|
166
157
|
copy('/test', 'HTTP_DESTINATION' => '/test').should be_forbidden
|
167
158
|
end
|
168
159
|
|
169
160
|
it 'should copy a single resource' do
|
170
|
-
put('/test', :input => 'body')
|
171
|
-
multi_status_ok.should eq true
|
161
|
+
put('/test', :input => 'body').should be_created
|
172
162
|
copy('/test', 'HTTP_DESTINATION' => '/copy')
|
173
163
|
multi_status_no_content.should eq true
|
174
164
|
get('/copy').body.should == 'body'
|
175
165
|
end
|
176
166
|
|
177
167
|
it 'should copy a resource with escaped characters' do
|
178
|
-
put(url_escape('/a b'), :input => 'body')
|
179
|
-
multi_status_ok.should eq true
|
168
|
+
put(url_escape('/a b'), :input => 'body').should be_created
|
180
169
|
copy(url_escape('/a b'), 'HTTP_DESTINATION' => url_escape('/a c'))
|
181
170
|
multi_status_no_content.should eq true
|
182
171
|
get(url_escape('/a c')).should be_ok
|
@@ -184,10 +173,8 @@ describe DAV4Rack::Handler do
|
|
184
173
|
end
|
185
174
|
|
186
175
|
it 'should deny a copy without overwrite' do
|
187
|
-
put('/test', :input => 'body')
|
188
|
-
|
189
|
-
put('/copy', :input => 'copy')
|
190
|
-
multi_status_ok.should eq true
|
176
|
+
put('/test', :input => 'body').should be_created
|
177
|
+
put('/copy', :input => 'copy').should be_created
|
191
178
|
copy('/test', 'HTTP_DESTINATION' => '/copy', 'HTTP_OVERWRITE' => 'F')
|
192
179
|
|
193
180
|
multistatus_response('/D:href').first.text.should =~ /http:\/\/localhost(:\d+)?\/test/
|
@@ -197,10 +184,8 @@ describe DAV4Rack::Handler do
|
|
197
184
|
end
|
198
185
|
|
199
186
|
it 'should allow a copy with overwrite' do
|
200
|
-
put('/test', :input => 'body')
|
201
|
-
|
202
|
-
put('/copy', :input => 'copy')
|
203
|
-
multi_status_ok.should eq true
|
187
|
+
put('/test', :input => 'body').should be_created
|
188
|
+
put('/copy', :input => 'copy').should be_created
|
204
189
|
copy('/test', 'HTTP_DESTINATION' => '/copy', 'HTTP_OVERWRITE' => 'T')
|
205
190
|
multi_status_no_content.should eq true
|
206
191
|
get('/copy').body.should == 'body'
|
@@ -218,10 +203,8 @@ describe DAV4Rack::Handler do
|
|
218
203
|
it 'should copy a collection resursively' do
|
219
204
|
mkcol('/folder')
|
220
205
|
multi_status_created.should eq true
|
221
|
-
put('/folder/a', :input => 'A')
|
222
|
-
|
223
|
-
put('/folder/b', :input => 'B')
|
224
|
-
multi_status_ok.should eq true
|
206
|
+
put('/folder/a', :input => 'A').should be_created
|
207
|
+
put('/folder/b', :input => 'B').should be_created
|
225
208
|
|
226
209
|
copy('/folder', 'HTTP_DESTINATION' => '/copy')
|
227
210
|
multi_status_ok.should eq true
|
@@ -234,10 +217,8 @@ describe DAV4Rack::Handler do
|
|
234
217
|
it 'should move a collection recursively' do
|
235
218
|
mkcol('/folder')
|
236
219
|
multi_status_created.should eq true
|
237
|
-
put('/folder/a', :input => 'A')
|
238
|
-
|
239
|
-
put('/folder/b', :input => 'B')
|
240
|
-
multi_status_ok.should eq true
|
220
|
+
put('/folder/a', :input => 'A').should be_created
|
221
|
+
put('/folder/b', :input => 'B').should be_created
|
241
222
|
|
242
223
|
move('/folder', 'HTTP_DESTINATION' => '/move')
|
243
224
|
multi_status_ok.should eq true
|
@@ -285,8 +266,7 @@ describe DAV4Rack::Handler do
|
|
285
266
|
end
|
286
267
|
|
287
268
|
it 'should find named properties' do
|
288
|
-
put('/test.html', :input => '<html/>')
|
289
|
-
multi_status_ok.should eq true
|
269
|
+
put('/test.html', :input => '<html/>').should be_created
|
290
270
|
propfind('/test.html', :input => propfind_xml(:getcontenttype, :getcontentlength))
|
291
271
|
|
292
272
|
multistatus_response('/D:propstat/D:prop/D:getcontenttype').first.text.should == 'text/html'
|
@@ -294,8 +274,7 @@ describe DAV4Rack::Handler do
|
|
294
274
|
end
|
295
275
|
|
296
276
|
it 'should lock a resource' do
|
297
|
-
put('/test', :input => 'body')
|
298
|
-
multi_status_ok.should eq true
|
277
|
+
put('/test', :input => 'body').should be_created
|
299
278
|
|
300
279
|
xml = render(:lockinfo) do |xml|
|
301
280
|
xml.lockscope { xml.exclusive }
|
@@ -329,9 +308,8 @@ describe DAV4Rack::Handler do
|
|
329
308
|
|
330
309
|
it "should return correct urls" do
|
331
310
|
# FIXME: a put to '/test' works, too -- should it?
|
332
|
-
put('/webdav/test', :input => 'body')
|
333
|
-
|
334
|
-
multistatus_response('/D:href').first.text.should =~ /http:\/\/localhost(:\d+)?\/webdav\/test/
|
311
|
+
put('/webdav/test', :input => 'body').should be_created
|
312
|
+
response.headers['content-location'].should =~ /http:\/\/localhost(:\d+)?\/webdav\/test/
|
335
313
|
end
|
336
314
|
end
|
337
315
|
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dav4rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 5
|
10
|
+
version: 0.2.5
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Chris Roberts
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-08-22 00:00:00 -07:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +26,11 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ~>
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 2
|
24
34
|
version: 1.4.2
|
25
35
|
type: :runtime
|
26
36
|
version_requirements: *id001
|
@@ -32,6 +42,11 @@ dependencies:
|
|
32
42
|
requirements:
|
33
43
|
- - ~>
|
34
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 9
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 1
|
49
|
+
- 1
|
35
50
|
version: 2.1.1
|
36
51
|
type: :runtime
|
37
52
|
version_requirements: *id002
|
@@ -43,6 +58,11 @@ dependencies:
|
|
43
58
|
requirements:
|
44
59
|
- - ">="
|
45
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 19
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 1
|
65
|
+
- 0
|
46
66
|
version: 1.1.0
|
47
67
|
type: :runtime
|
48
68
|
version_requirements: *id003
|
@@ -89,12 +109,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
109
|
requirements:
|
90
110
|
- - ">="
|
91
111
|
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
92
115
|
version: "0"
|
93
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
117
|
none: false
|
95
118
|
requirements:
|
96
119
|
- - ">="
|
97
120
|
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
98
124
|
version: "0"
|
99
125
|
requirements: []
|
100
126
|
|