Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add field Net::DAV#last_status that contains the last status as retur…

…ned by the server.

Conflicts:

	spec/integration/net_dav_spec.rb
  • Loading branch information...
commit 1660128225e23213252f87384accdd3b6ee99b5e 1 parent dd6d52e
Lennaert Meijvogel authored
Showing with 28 additions and 0 deletions.
  1. +14 −0 lib/net/dav.rb
  2. +14 −0 spec/integration/net_dav_spec.rb
View
14 lib/net/dav.rb
@@ -13,10 +13,17 @@ module Net #:nodoc:
# Implement a WebDAV client
class DAV
MAX_REDIRECTS = 10
+
+ def last_status
+ @handler.last_status
+ end
+
class NetHttpHandler
attr_writer :user, :pass
attr_accessor :disable_basic_auth
+ attr_reader :last_status
+
def verify_callback=(callback)
@http.verify_callback = callback
@@ -156,6 +163,8 @@ def handle_request(req, headers, limit = MAX_REDIRECTS, &block)
else
response = @http.request(req)
end
+
+ @last_status = response.code.to_i
case response
when Net::HTTPSuccess then
return response
@@ -283,6 +292,9 @@ def request_returning_body(verb, path, headers)
end
end
curl.perform
+
+ @last_status = curl.response_code
+
unless curl.response_code >= 200 && curl.response_code < 300
header_block = curl.header_str.split(/\r?\n\r?\n/)[-1]
msg = header_block.split(/\r?\n/)[0]
@@ -348,6 +360,8 @@ def self.start(uri, options = nil, &block) # :yield: dav
# You can pass :curl => false if you want to disable use
# of the curb (libcurl) gem if present for acceleration
def initialize(uri, options = nil)
+ @last_status = 0
+
@have_curl = Curl rescue nil
if options && options.has_key?(:curl) && !options[:curl]
@have_curl = false
View
14 spec/integration/net_dav_spec.rb
@@ -36,6 +36,13 @@
@props.should match(/200 OK/)
end
+ it "should store the HTTP status in @status" do
+ dav = Net::DAV.new("http://localhost:10080/")
+ @props = dav.propfind("/").to_s
+
+ dav.last_status.should == 207
+ end
+
it "should raise if finding non-existent path" do
lambda do
@dav.find("/") do |item|
@@ -55,6 +62,7 @@
@props.should match(/404.*Not found/i)
@dav.put_string(@new_file_uri,"File contents")
+ dav.last_status.should == 200
@props = find_props_or_error(@dav, @new_file_uri )
@props.should match(/200 OK/i)
@@ -67,8 +75,11 @@
@props.should match(/200 OK/i)
@dav.delete(@new_file_uri)
+ dav.last_status.should == 204
+
@props = find_props_or_error(@dav, @new_file_uri)
@props.should match(/404.*Not found/i)
+
end
it "should copy files on webdav server" do
@@ -76,6 +87,7 @@
@props.should match(/200 OK/i)
@dav.copy("/file.html", @copied_file_uri)
+ dav.last_status.should == 201
@props = find_props_or_error(@dav, @copied_file_uri)
@props.should match(/200 OK/i)
@@ -91,6 +103,8 @@
@props.should match(/200 OK/i)
@dav.move("/file.html", @moved_file_uri)
+ dav.last_status.should == 201
+
@props = find_props_or_error(@dav, @moved_file_uri)
@props.should match(/200 OK/i)
Please sign in to comment.
Something went wrong with that request. Please try again.