13 Commits
0 ... 4

Author SHA1 Message Date
Christoph Polcin
f60c73fbb4 Merge pull request #8 from Ferada/fix-read-status-code
Handle error response when reading a file.
2017-12-20 19:29:10 +01:00
Olof-Joachim Frahm
a11466bd13 Handle error response when reading a file. 2017-12-20 10:53:49 +01:00
Christoph Polcin
e3cd1f98e7 Merge pull request #6 from ProgramYazar/master
fix delete for yandex
2017-09-19 07:22:16 +02:00
Christoph Polcin
e3a31466a7 Merge pull request #4 from ayllon/master
Add SetTransport method
2017-09-19 07:19:23 +02:00
Engin KIZILGÜN
2b5dab74d3 fix delete for yandex
204 success added
2017-09-18 15:54:19 +03:00
Alejandro Alvarez Ayllon
79a29f3ad5 Add SetTransport method 2017-08-07 12:13:13 +02:00
Christoph Polcin
a03a0a3645 Merge pull request #3 from deyring/master
SetHeader method added to client
2017-04-12 17:59:32 +02:00
Daniel Eyring
12fe295146 SetHeader method added to client 2016-07-27 14:36:21 +02:00
Christoph Polcin
8f99657223 client: dry 2015-12-09 10:02:37 +01:00
Christoph Polcin
b12f1c1b33 Merge pull request #2 from mattn/handle-href
look href if displayname not exists

thanks!
2015-12-09 09:56:31 +01:00
Yasuhiro Matsumoto
33816041d6 Use href instead of displayname for Name() 2015-12-09 17:35:24 +09:00
Christoph Polcin
31c3cc07c7 Merge pull request #1 from mattn/fix-directory-timestamp
directory should have mod-time
2015-12-09 09:32:20 +01:00
Yasuhiro Matsumoto
87bbafc0c0 directory should have mod-time 2015-11-16 22:41:20 +09:00

View File

@@ -6,7 +6,9 @@ import (
"encoding/xml" "encoding/xml"
"io" "io"
"net/http" "net/http"
"net/url"
"os" "os"
pathpkg "path"
"strings" "strings"
"time" "time"
) )
@@ -31,6 +33,14 @@ func NewClient(uri string, user string, pw string) *Client {
return c return c
} }
func (c *Client) SetHeader(key, value string) {
c.headers.Add(key, value)
}
func (c *Client) SetTransport(transport http.RoundTripper) {
c.c.Transport = transport
}
func (c *Client) Connect() error { func (c *Client) Connect() error {
rs, err := c.options("/") rs, err := c.options("/")
if err == nil { if err == nil {
@@ -84,17 +94,20 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
if p := getProps(r, "200"); p != nil { if p := getProps(r, "200"); p != nil {
f := new(File) f := new(File)
if ps, err := url.QueryUnescape(r.Href); err == nil {
f.name = pathpkg.Base(ps)
} else {
f.name = p.Name f.name = p.Name
}
f.path = path + f.name f.path = path + f.name
f.modified = parseModified(&p.Modified)
if p.Type.Local == "collection" { if p.Type.Local == "collection" {
f.path += "/" f.path += "/"
f.size = 0 f.size = 0
f.modified = time.Unix(0, 0)
f.isdir = true f.isdir = true
} else { } else {
f.size = parseInt64(&p.Size) f.size = parseInt64(&p.Size)
f.modified = parseModified(&p.Modified)
f.isdir = false f.isdir = false
} }
@@ -183,7 +196,7 @@ func (c *Client) RemoveAll(path string) error {
} }
rs.Body.Close() rs.Body.Close()
if rs.StatusCode == 200 || rs.StatusCode == 404 { if rs.StatusCode == 200 || rs.StatusCode == 204 || rs.StatusCode == 404 {
return nil return nil
} else { } else {
return newPathError("Remove", path, rs.StatusCode) return newPathError("Remove", path, rs.StatusCode)
@@ -248,7 +261,12 @@ func (c *Client) ReadStream(path string) (io.ReadCloser, error) {
if err != nil { if err != nil {
return nil, newPathErrorErr("ReadStream", path, err) return nil, newPathErrorErr("ReadStream", path, err)
} }
if rs.StatusCode == 200 {
return rs.Body, nil return rs.Body, nil
} else {
rs.Body.Close()
return nil, newPathError("ReadStream", path, rs.StatusCode)
}
} }
func (c *Client) Write(path string, data []byte, _ os.FileMode) error { func (c *Client) Write(path string, data []byte, _ os.FileMode) error {