Connect() will fail on non collection roots

This commit is contained in:
Christoph Polcin 2014-10-24 12:40:49 +02:00
parent f728828956
commit b8d7beb48c
2 changed files with 6 additions and 9 deletions

View File

@ -3,7 +3,6 @@ package gowebdav
import ( import (
"encoding/base64" "encoding/base64"
"encoding/xml" "encoding/xml"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
@ -32,20 +31,18 @@ func NewClient(uri string, user string, pw string) *Client {
} }
func (c *Client) Connect() error { func (c *Client) Connect() error {
if rs, err := c.options("/"); err == nil { rs, err := c.options("/")
if err == nil {
defer rs.Body.Close() defer rs.Body.Close()
if rs.StatusCode != 200 || (rs.Header.Get("Dav") == "" && rs.Header.Get("DAV") == "") { if rs.StatusCode != 200 || (rs.Header.Get("Dav") == "" && rs.Header.Get("DAV") == "") {
return errors.New(fmt.Sprintf("Bad Request: %d - %s", rs.StatusCode, c.root)) return newPathError("Connect", c.root, rs.StatusCode)
} }
// TODO check PROPFIND if path is collection _, err = c.ReadDir("/")
}
return nil
} else {
return err return err
} }
}
type props struct { type props struct {
Status string `xml:"DAV: status"` Status string `xml:"DAV: status"`

View File

@ -36,7 +36,7 @@ func main() {
c := d.NewClient(*root, *usr, *pw) c := d.NewClient(*root, *usr, *pw)
if err := c.Connect(); err != nil { if err := c.Connect(); err != nil {
Fail(err) Fail(fmt.Sprintf("Failed to connect due to: %s", err.Error()))
} }
if len(flag.Args()) > 0 { if len(flag.Args()) > 0 {