Webdav

The :webdav plugin adds convenience methods to handle common WebDav protocol operations, such as:

  • MKCOL (via #mkcol(dir))
  • COPY (via #copy(src, dest))
  • MOVE (via #move(src, dest))
  • LOCK (via #lock(path))
  • UNLOCK (via #unlock(path, lock_token))
  • PROPFIND (via #propfind(path))
  • PROPPATCH (via #proppatch(path, props))

other operations, such as PUT, PATCH, GET, are already supported OTTB by httpx.

It’s best used in combination with other httpx features, as described below.

How to use

require "httpx"

# use the :origin option to set the webdav server for all subsequent operations, so you only deal with paths
webdav = HTTPX.plugin(:webdav, origin: "http://webdav-server")

# Use one of the authentication plugins to login: https://gitlab.com/os85/httpx/-/wikis/Authentication
# basic auth example
webdav = HTTPX.plugin(:basic_authentication).basic_auth("user", "pass")
# digest auth example
webdav = HTTPX.plugin(:digest_authentication).digest_auth("user", "pass")

# GET, PUT, HEAD do not change
res = webdav.put("/file.html", body: "this is the file body")
# MKCOL
res = webdav.mkcol("/newdir") # res.status should be 201 if succeeds
# COPY
res = webdav.copy("/file.html", "/newdir/copy.html")
# MOVE
res = webdav.move("/file.html", "/newdir/copy.html")
# LOCK/UNLOCK
lock_res = webdav.lock("/file.html")
unlock_res = webdav.unlock("/file.html", lock_res.headers["lock-token"])
# or, using the block form:
webdav.lock("/file.html") do |_lock_res|
  # do something
end # unlocked
# PROPFIND
# gets all props
res = webdav.propfind("/file.html")
# getting named props
res = webdav.propfind("/file.html", <<-XML
  <?xml version="1.0" encoding="utf-8" ?>
  <D:propfind xmlns:D="DAV:">
    <D:prop xmlns:R="http://ns.example.com/boxschema/">
      <R:bigbox/>
      <R:author/>
      <R:DingALing/>
      <R:Random/>
    </D:prop>
  </D:propfind>
XML
)
# PROPPATCH
res = webdav.proppatch("/file.html", <<-XML
  <D:set>
    <D:prop>
      <Z:Authors>
        <Z:Author>Jim Whitehead</Z:Author>
        <Z:Author>Roy Fielding</Z:Author>
      </Z:Authors>
    </D:prop>
  </D:set>
  <D:remove>
    <D:prop><Z:Copyright-Owner/></D:prop>
  </D:remove>
XML
)

Next: OAuth