remove all debug

This commit is contained in:
shoopea 2024-01-20 12:33:07 +01:00
parent d8c0f204df
commit f073d3021d
4 changed files with 0 additions and 74 deletions

30
auth.go
View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"io" "io"
"log"
"net/http" "net/http"
"strings" "strings"
"sync" "sync"
@ -108,7 +107,6 @@ type noAuth struct{}
// and the remotely offered authentication methods. // and the remotely offered authentication methods.
// First In, First Out. // First In, First Out.
func NewAutoAuth(login string, secret string) Authorizer { func NewAutoAuth(login string, secret string) Authorizer {
log.Printf("NewAutoAuth(%s, %s)", login, secret)
fmap := make([]authfactory, 0) fmap := make([]authfactory, 0)
az := &authorizer{factories: fmap, defAuthMux: sync.Mutex{}, defAuth: &nullAuth{}} az := &authorizer{factories: fmap, defAuthMux: sync.Mutex{}, defAuth: &nullAuth{}}
@ -132,7 +130,6 @@ func NewAutoAuth(login string, secret string) Authorizer {
// First In, First Out. // First In, First Out.
// It offers the `NewAutoAuth` features. // It offers the `NewAutoAuth` features.
func NewEmptyAuth() Authorizer { func NewEmptyAuth() Authorizer {
log.Printf("NewEmptyAuth()")
fmap := make([]authfactory, 0) fmap := make([]authfactory, 0)
az := &authorizer{factories: fmap, defAuthMux: sync.Mutex{}, defAuth: &nullAuth{}} az := &authorizer{factories: fmap, defAuthMux: sync.Mutex{}, defAuth: &nullAuth{}}
return az return az
@ -149,13 +146,11 @@ func NewEmptyAuth() Authorizer {
// without any synchronisation!! // without any synchronisation!!
// Still applicable with `BasicAuth` within go routines. // Still applicable with `BasicAuth` within go routines.
func NewPreemptiveAuth(auth Authenticator) Authorizer { func NewPreemptiveAuth(auth Authenticator) Authorizer {
log.Printf("NewPreemptiveAuth()")
return &preemptiveAuthorizer{auth: auth} return &preemptiveAuthorizer{auth: auth}
} }
// NewAuthenticator creates an Authenticator (Shim) per request // NewAuthenticator creates an Authenticator (Shim) per request
func (a *authorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) { func (a *authorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) {
log.Printf("authorizer.NewAuthenticator()")
var retryBuf io.Reader = body var retryBuf io.Reader = body
if body != nil { if body != nil {
// If the authorization fails, we will need to restart reading // If the authorization fails, we will need to restart reading
@ -182,7 +177,6 @@ func (a *authorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader)
// AddAuthenticator appends the AuthFactory to our factories. // AddAuthenticator appends the AuthFactory to our factories.
// It converts the key to lower case and preserves the order. // It converts the key to lower case and preserves the order.
func (a *authorizer) AddAuthenticator(key string, fn AuthFactory) { func (a *authorizer) AddAuthenticator(key string, fn AuthFactory) {
log.Printf("authorizer.AddAuthenticator(%s)", key)
key = strings.ToLower(key) key = strings.ToLower(key)
for _, f := range a.factories { for _, f := range a.factories {
if f.key == key { if f.key == key {
@ -194,7 +188,6 @@ func (a *authorizer) AddAuthenticator(key string, fn AuthFactory) {
// factory picks all valid Authenticators based on Www-Authenticate headers // factory picks all valid Authenticators based on Www-Authenticate headers
func (a *authorizer) factory(c *http.Client, rs *http.Response, path string) (auth Authenticator, err error) { func (a *authorizer) factory(c *http.Client, rs *http.Response, path string) (auth Authenticator, err error) {
log.Printf("authorizer.factory()")
headers := rs.Header.Values("Www-Authenticate") headers := rs.Header.Values("Www-Authenticate")
if len(headers) > 0 { if len(headers) > 0 {
auths := make([]Authenticator, 0) auths := make([]Authenticator, 0)
@ -230,7 +223,6 @@ func (a *authorizer) factory(c *http.Client, rs *http.Response, path string) (au
// setDefaultAuthenticator sets the default Authenticator // setDefaultAuthenticator sets the default Authenticator
func (a *authorizer) setDefaultAuthenticator(auth Authenticator) { func (a *authorizer) setDefaultAuthenticator(auth Authenticator) {
log.Printf("authorizer.setDefaultAuthenticator()")
a.defAuthMux.Lock() a.defAuthMux.Lock()
a.defAuth.Close() a.defAuth.Close()
a.defAuth = auth a.defAuth = auth
@ -239,7 +231,6 @@ func (a *authorizer) setDefaultAuthenticator(auth Authenticator) {
// Authorize the current request // Authorize the current request
func (s *authShim) Authorize(c *http.Client, rq *http.Request, path string) error { func (s *authShim) Authorize(c *http.Client, rq *http.Request, path string) error {
log.Printf("authShim.Authorize()")
if err := s.auth.Authorize(c, rq, path); err != nil { if err := s.auth.Authorize(c, rq, path); err != nil {
return err return err
} }
@ -261,7 +252,6 @@ func (s *authShim) Authorize(c *http.Client, rq *http.Request, path string) erro
// Verify checks for authentication issues and may trigger a re-authentication. // Verify checks for authentication issues and may trigger a re-authentication.
// Catches AlgoChangedErr to update the current Authenticator // Catches AlgoChangedErr to update the current Authenticator
func (s *authShim) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) { func (s *authShim) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) {
log.Printf("authShim.Verify()")
redo, err = s.auth.Verify(c, rs, path) redo, err = s.auth.Verify(c, rs, path)
if err != nil && errors.Is(err, ErrAuthChanged) { if err != nil && errors.Is(err, ErrAuthChanged) {
if auth, aerr := s.factory(c, rs, path); aerr == nil { if auth, aerr := s.factory(c, rs, path); aerr == nil {
@ -277,7 +267,6 @@ func (s *authShim) Verify(c *http.Client, rs *http.Response, path string) (redo
// Close closes all resources // Close closes all resources
func (s *authShim) Close() error { func (s *authShim) Close() error {
log.Printf("authShim.Close()")
s.auth.Close() s.auth.Close()
s.auth, s.factory = nil, nil s.auth, s.factory = nil, nil
if s.body != nil { if s.body != nil {
@ -291,19 +280,16 @@ func (s *authShim) Close() error {
// It's not intend to Clone the shim // It's not intend to Clone the shim
// therefore it returns a noAuth instance // therefore it returns a noAuth instance
func (s *authShim) Clone() Authenticator { func (s *authShim) Clone() Authenticator {
log.Printf("authShim.Clone()")
return &noAuth{} return &noAuth{}
} }
// String toString // String toString
func (s *authShim) String() string { func (s *authShim) String() string {
log.Printf("authShim.String()")
return "AuthShim" return "AuthShim"
} }
// Authorize authorizes the current request with the top most Authorizer // Authorize authorizes the current request with the top most Authorizer
func (n *negoAuth) Authorize(c *http.Client, rq *http.Request, path string) error { func (n *negoAuth) Authorize(c *http.Client, rq *http.Request, path string) error {
log.Printf("negoAuth.Authorize()")
if len(n.auths) == 0 { if len(n.auths) == 0 {
return NewPathError("NoAuthenticator", path, 400) return NewPathError("NoAuthenticator", path, 400)
} }
@ -312,7 +298,6 @@ func (n *negoAuth) Authorize(c *http.Client, rq *http.Request, path string) erro
// Verify verifies the authentication and selects the next one based on the result // Verify verifies the authentication and selects the next one based on the result
func (n *negoAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) { func (n *negoAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) {
log.Printf("negoAuth.Verify()")
if len(n.auths) == 0 { if len(n.auths) == 0 {
return false, NewPathError("NoAuthenticator", path, 400) return false, NewPathError("NoAuthenticator", path, 400)
} }
@ -337,7 +322,6 @@ func (n *negoAuth) Verify(c *http.Client, rs *http.Response, path string) (redo
// Close will close the underlying authenticators. // Close will close the underlying authenticators.
func (n *negoAuth) Close() error { func (n *negoAuth) Close() error {
log.Printf("negoAuth.Close()")
for _, a := range n.auths { for _, a := range n.auths {
a.Close() a.Close()
} }
@ -347,7 +331,6 @@ func (n *negoAuth) Close() error {
// Clone clones the underlying authenticators. // Clone clones the underlying authenticators.
func (n *negoAuth) Clone() Authenticator { func (n *negoAuth) Clone() Authenticator {
log.Printf("negoAuth.Clone()")
auths := make([]Authenticator, len(n.auths)) auths := make([]Authenticator, len(n.auths))
for i, e := range n.auths { for i, e := range n.auths {
auths[i] = e.Clone() auths[i] = e.Clone()
@ -356,19 +339,16 @@ func (n *negoAuth) Clone() Authenticator {
} }
func (n *negoAuth) String() string { func (n *negoAuth) String() string {
log.Printf("negoAuth.String()")
return "NegoAuth" return "NegoAuth"
} }
// Authorize the current request // Authorize the current request
func (n *noAuth) Authorize(c *http.Client, rq *http.Request, path string) error { func (n *noAuth) Authorize(c *http.Client, rq *http.Request, path string) error {
log.Printf("noAuth.Authorize()")
return nil return nil
} }
// Verify checks for authentication issues and may trigger a re-authentication // Verify checks for authentication issues and may trigger a re-authentication
func (n *noAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) { func (n *noAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) {
log.Printf("noAuth.Verify()")
if "" != rs.Header.Get("Www-Authenticate") { if "" != rs.Header.Get("Www-Authenticate") {
err = ErrAuthChanged err = ErrAuthChanged
} }
@ -377,63 +357,53 @@ func (n *noAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bo
// Close closes all resources // Close closes all resources
func (n *noAuth) Close() error { func (n *noAuth) Close() error {
log.Printf("noAuth.Close()")
return nil return nil
} }
// Clone creates a copy of itself // Clone creates a copy of itself
func (n *noAuth) Clone() Authenticator { func (n *noAuth) Clone() Authenticator {
log.Printf("noAuth.Clone()")
// no copy due to read only access // no copy due to read only access
return n return n
} }
// String toString // String toString
func (n *noAuth) String() string { func (n *noAuth) String() string {
log.Printf("noAuth.String()")
return "NoAuth" return "NoAuth"
} }
// Authorize the current request // Authorize the current request
func (n *nullAuth) Authorize(c *http.Client, rq *http.Request, path string) error { func (n *nullAuth) Authorize(c *http.Client, rq *http.Request, path string) error {
log.Printf("nullAuth.Authorize()")
rq.Header.Set(XInhibitRedirect, "1") rq.Header.Set(XInhibitRedirect, "1")
return nil return nil
} }
// Verify checks for authentication issues and may trigger a re-authentication // Verify checks for authentication issues and may trigger a re-authentication
func (n *nullAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) { func (n *nullAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) {
log.Printf("nullAuth.Verify()")
return true, ErrAuthChanged return true, ErrAuthChanged
} }
// Close closes all resources // Close closes all resources
func (n *nullAuth) Close() error { func (n *nullAuth) Close() error {
log.Printf("nullAuth.Close()")
return nil return nil
} }
// Clone creates a copy of itself // Clone creates a copy of itself
func (n *nullAuth) Clone() Authenticator { func (n *nullAuth) Clone() Authenticator {
log.Printf("nullAuth.Clone()")
// no copy due to read only access // no copy due to read only access
return n return n
} }
// String toString // String toString
func (n *nullAuth) String() string { func (n *nullAuth) String() string {
log.Printf("nullAuth.String()")
return "NullAuth" return "NullAuth"
} }
// NewAuthenticator creates an Authenticator (Shim) per request // NewAuthenticator creates an Authenticator (Shim) per request
func (b *preemptiveAuthorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) { func (b *preemptiveAuthorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) {
log.Printf("preemptiveAuthorizer.NewAuthenticator()")
return b.auth.Clone(), body return b.auth.Clone(), body
} }
// AddAuthenticator Will PANIC because it may only have a single authentication method // AddAuthenticator Will PANIC because it may only have a single authentication method
func (b *preemptiveAuthorizer) AddAuthenticator(key string, fn AuthFactory) { func (b *preemptiveAuthorizer) AddAuthenticator(key string, fn AuthFactory) {
log.Printf("preemptiveAuthorizer.AddAuthenticator()")
panic("You're funny! A preemptive authorizer may only have a single authentication method") panic("You're funny! A preemptive authorizer may only have a single authentication method")
} }

View File

@ -2,7 +2,6 @@ package gowebdav
import ( import (
"fmt" "fmt"
"log"
"net/http" "net/http"
) )
@ -20,13 +19,11 @@ func NewBasicAuth(login, secret string) (Authenticator, error) {
// Authorize the current request // Authorize the current request
func (b *BasicAuth) Authorize(c *http.Client, rq *http.Request, path string) error { func (b *BasicAuth) Authorize(c *http.Client, rq *http.Request, path string) error {
rq.SetBasicAuth(b.user, b.pw) rq.SetBasicAuth(b.user, b.pw)
log.Printf("BasicAuth.Authorize : SetBasicAuth(%s, %s)", b.user, b.pw)
return nil return nil
} }
// Verify verifies if the authentication // Verify verifies if the authentication
func (b *BasicAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) { func (b *BasicAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) {
log.Printf("BasicAuth.Verify : StatusCode = %d", rs.StatusCode)
if rs.StatusCode == 401 { if rs.StatusCode == 401 {
err = NewPathError("Authorize", path, rs.StatusCode) err = NewPathError("Authorize", path, rs.StatusCode)
} }
@ -35,19 +32,16 @@ func (b *BasicAuth) Verify(c *http.Client, rs *http.Response, path string) (redo
// Close cleans up all resources // Close cleans up all resources
func (b *BasicAuth) Close() error { func (b *BasicAuth) Close() error {
log.Printf("BasicAuth.Close")
return nil return nil
} }
// Clone creates a Copy of itself // Clone creates a Copy of itself
func (b *BasicAuth) Clone() Authenticator { func (b *BasicAuth) Clone() Authenticator {
log.Printf("BasicAuth.Clone")
// no copy due to read only access // no copy due to read only access
return b return b
} }
// String toString // String toString
func (b *BasicAuth) String() string { func (b *BasicAuth) String() string {
log.Printf("BasicAuth.String")
return fmt.Sprintf("BasicAuth login: %s", b.user) return fmt.Sprintf("BasicAuth login: %s", b.user)
} }

View File

@ -5,7 +5,6 @@ import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -27,13 +26,11 @@ type Client struct {
// NewClient creates a new instance of client // NewClient creates a new instance of client
func NewClient(uri, user, pw string) *Client { func NewClient(uri, user, pw string) *Client {
log.Printf("NewClient(%s, %s, %s)", uri, user, pw)
return NewAuthClient(uri, NewAutoAuth(user, pw)) return NewAuthClient(uri, NewAutoAuth(user, pw))
} }
// NewAuthClient creates a new client instance with a custom Authorizer // NewAuthClient creates a new client instance with a custom Authorizer
func NewAuthClient(uri string, auth Authorizer) *Client { func NewAuthClient(uri string, auth Authorizer) *Client {
log.Printf("NewAuthClient(%s)", uri)
c := &http.Client{ c := &http.Client{
CheckRedirect: func(rq *http.Request, via []*http.Request) error { CheckRedirect: func(rq *http.Request, via []*http.Request) error {
if len(via) >= 10 { if len(via) >= 10 {
@ -50,37 +47,31 @@ func NewAuthClient(uri string, auth Authorizer) *Client {
// SetHeader lets us set arbitrary headers for a given client // SetHeader lets us set arbitrary headers for a given client
func (c *Client) SetHeader(key, value string) { func (c *Client) SetHeader(key, value string) {
log.Printf("Client.SetHeader(%s, %s)", key, value)
c.headers.Add(key, value) c.headers.Add(key, value)
} }
// SetInterceptor lets us set an arbitrary interceptor for a given client // SetInterceptor lets us set an arbitrary interceptor for a given client
func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request)) { func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request)) {
log.Printf("Client.SetInterceptor()")
c.interceptor = interceptor c.interceptor = interceptor
} }
// SetTimeout exposes the ability to set a time limit for requests // SetTimeout exposes the ability to set a time limit for requests
func (c *Client) SetTimeout(timeout time.Duration) { func (c *Client) SetTimeout(timeout time.Duration) {
log.Printf("Client.SetTimeout()")
c.c.Timeout = timeout c.c.Timeout = timeout
} }
// SetTransport exposes the ability to define custom transports // SetTransport exposes the ability to define custom transports
func (c *Client) SetTransport(transport http.RoundTripper) { func (c *Client) SetTransport(transport http.RoundTripper) {
log.Printf("Client.SetTransport()")
c.c.Transport = transport c.c.Transport = transport
} }
// SetJar exposes the ability to set a cookie jar to the client. // SetJar exposes the ability to set a cookie jar to the client.
func (c *Client) SetJar(jar http.CookieJar) { func (c *Client) SetJar(jar http.CookieJar) {
log.Printf("Client.SetJar()")
c.c.Jar = jar c.c.Jar = jar
} }
// Connect connects to our dav server // Connect connects to our dav server
func (c *Client) Connect() error { func (c *Client) Connect() error {
log.Printf("Client.Connect()")
rs, err := c.options("/") rs, err := c.options("/")
if err != nil { if err != nil {
return err return err
@ -114,7 +105,6 @@ type response struct {
} }
func getProps(r *response, status string) *props { func getProps(r *response, status string) *props {
log.Printf("getProps()")
for _, prop := range r.Props { for _, prop := range r.Props {
if strings.Contains(prop.Status, status) { if strings.Contains(prop.Status, status) {
return &prop return &prop
@ -125,7 +115,6 @@ func getProps(r *response, status string) *props {
// ReadDir reads the contents of a remote directory // ReadDir reads the contents of a remote directory
func (c *Client) ReadDir(path string) ([]os.FileInfo, error) { func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
log.Printf("Client.ReadDir(%s)", path)
path = FixSlashes(path) path = FixSlashes(path)
files := make([]os.FileInfo, 0) files := make([]os.FileInfo, 0)
skipSelf := true skipSelf := true
@ -193,7 +182,6 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
// Stat returns the file stats for a specified path // Stat returns the file stats for a specified path
func (c *Client) Stat(path string) (os.FileInfo, error) { func (c *Client) Stat(path string) (os.FileInfo, error) {
log.Printf("Client.Stat(%s)", path)
var f *File var f *File
parse := func(resp interface{}) error { parse := func(resp interface{}) error {
r := resp.(*response) r := resp.(*response)
@ -246,13 +234,11 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
// Remove removes a remote file // Remove removes a remote file
func (c *Client) Remove(path string) error { func (c *Client) Remove(path string) error {
log.Printf("Client.Remove(%s)", path)
return c.RemoveAll(path) return c.RemoveAll(path)
} }
// RemoveAll removes remote files // RemoveAll removes remote files
func (c *Client) RemoveAll(path string) error { func (c *Client) RemoveAll(path string) error {
log.Printf("Client.RemoveAll(%s)", path)
rs, err := c.req("DELETE", path, nil, nil) rs, err := c.req("DELETE", path, nil, nil)
if err != nil { if err != nil {
return NewPathError("Remove", path, 400) return NewPathError("Remove", path, 400)
@ -271,7 +257,6 @@ func (c *Client) RemoveAll(path string) error {
// Mkdir makes a directory // Mkdir makes a directory
func (c *Client) Mkdir(path string, _ os.FileMode) (err error) { func (c *Client) Mkdir(path string, _ os.FileMode) (err error) {
log.Printf("Client.Mkdir(%s)", path)
path = FixSlashes(path) path = FixSlashes(path)
status, err := c.mkcol(path) status, err := c.mkcol(path)
if err != nil { if err != nil {
@ -286,7 +271,6 @@ func (c *Client) Mkdir(path string, _ os.FileMode) (err error) {
// MkdirAll like mkdir -p, but for webdav // MkdirAll like mkdir -p, but for webdav
func (c *Client) MkdirAll(path string, _ os.FileMode) (err error) { func (c *Client) MkdirAll(path string, _ os.FileMode) (err error) {
log.Printf("Client.MkdirAll(%s)", path)
path = FixSlashes(path) path = FixSlashes(path)
status, err := c.mkcol(path) status, err := c.mkcol(path)
if err != nil { if err != nil {
@ -319,19 +303,16 @@ func (c *Client) MkdirAll(path string, _ os.FileMode) (err error) {
// Rename moves a file from A to B // Rename moves a file from A to B
func (c *Client) Rename(oldpath, newpath string, overwrite bool) error { func (c *Client) Rename(oldpath, newpath string, overwrite bool) error {
log.Printf("Client.Rename(%s, %s)", oldpath, newpath)
return c.copymove("MOVE", oldpath, newpath, overwrite) return c.copymove("MOVE", oldpath, newpath, overwrite)
} }
// Copy copies a file from A to B // Copy copies a file from A to B
func (c *Client) Copy(oldpath, newpath string, overwrite bool) error { func (c *Client) Copy(oldpath, newpath string, overwrite bool) error {
log.Printf("Client.Copy(%s, %s)", oldpath, newpath)
return c.copymove("COPY", oldpath, newpath, overwrite) return c.copymove("COPY", oldpath, newpath, overwrite)
} }
// Read reads the contents of a remote file // Read reads the contents of a remote file
func (c *Client) Read(path string) ([]byte, error) { func (c *Client) Read(path string) ([]byte, error) {
log.Printf("Client.Read(%s)", path)
var stream io.ReadCloser var stream io.ReadCloser
var err error var err error
@ -350,7 +331,6 @@ func (c *Client) Read(path string) ([]byte, error) {
// ReadStream reads the stream for a given path // ReadStream reads the stream for a given path
func (c *Client) ReadStream(path string) (io.ReadCloser, error) { func (c *Client) ReadStream(path string) (io.ReadCloser, error) {
log.Printf("Client.ReadStream(%s)", path)
rs, err := c.req("GET", path, nil, nil) rs, err := c.req("GET", path, nil, nil)
if err != nil { if err != nil {
return nil, NewPathErrorErr("ReadStream", path, err) return nil, NewPathErrorErr("ReadStream", path, err)
@ -373,7 +353,6 @@ func (c *Client) ReadStream(path string) (io.ReadCloser, error) {
// this function will emulate the behavior by skipping `offset` bytes and limiting the result // this function will emulate the behavior by skipping `offset` bytes and limiting the result
// to `length`. // to `length`.
func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error) { func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error) {
log.Printf("Client.ReadStreamRange(%s)", path)
rs, err := c.req("GET", path, nil, func(r *http.Request) { rs, err := c.req("GET", path, nil, func(r *http.Request) {
if length > 0 { if length > 0 {
r.Header.Add("Range", fmt.Sprintf("bytes=%d-%d", offset, offset+length-1)) r.Header.Add("Range", fmt.Sprintf("bytes=%d-%d", offset, offset+length-1))
@ -408,7 +387,6 @@ func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadClos
// Write writes data to a given path // Write writes data to a given path
func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) { func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
log.Printf("Client.Write(%s)", path)
s, err := c.put(path, bytes.NewReader(data)) s, err := c.put(path, bytes.NewReader(data))
if err != nil { if err != nil {
return return
@ -439,7 +417,6 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
// WriteStream writes a stream // WriteStream writes a stream
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error) { func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error) {
log.Printf("Client.WriteStream(%s)", path)
err = c.createParentCollection(path) err = c.createParentCollection(path)
if err != nil { if err != nil {

View File

@ -9,7 +9,6 @@ import (
) )
func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (rs *http.Response, err error) { func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (rs *http.Response, err error) {
log.Printf("Client.req(%s, %s)", method, path)
var redo bool var redo bool
var r *http.Request var r *http.Request
var uri = PathEscape(Join(c.root, path)) var uri = PathEscape(Join(c.root, path))
@ -17,19 +16,16 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
defer auth.Close() defer auth.Close()
for { // TODO auth.continue() strategy(true|n times|until)? for { // TODO auth.continue() strategy(true|n times|until)?
log.Printf("Client.req(%s, %s) : NewRequest", method, path)
if r, err = http.NewRequest(method, uri, body); err != nil { if r, err = http.NewRequest(method, uri, body); err != nil {
return return
} }
log.Printf("Client.req(%s, %s) : Adding headers", method, path)
for k, vals := range c.headers { for k, vals := range c.headers {
for _, v := range vals { for _, v := range vals {
r.Header.Add(k, v) r.Header.Add(k, v)
} }
} }
log.Printf("Client.req(%s, %s) : Authorize", method, path)
if err = auth.Authorize(c.c, r, path); err != nil { if err = auth.Authorize(c.c, r, path); err != nil {
return return
} }
@ -42,12 +38,10 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
c.interceptor(method, r) c.interceptor(method, r)
} }
log.Printf("Client.req(%s, %s) : Do", method, path)
if rs, err = c.c.Do(r); err != nil { if rs, err = c.c.Do(r); err != nil {
return return
} }
log.Printf("Client.req(%s, %s) : Verify", method, path)
if redo, err = auth.Verify(c.c, rs, path); err != nil { if redo, err = auth.Verify(c.c, rs, path); err != nil {
rs.Body.Close() rs.Body.Close()
return nil, err return nil, err
@ -62,13 +56,10 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
break break
} }
log.Printf("Client.req(%s, %s) : done", method, path)
return rs, err return rs, err
} }
func (c *Client) mkcol(path string) (status int, err error) { func (c *Client) mkcol(path string) (status int, err error) {
log.Printf("Client.mkcol(%s)", path)
rs, err := c.req("MKCOL", path, nil, nil) rs, err := c.req("MKCOL", path, nil, nil)
if err != nil { if err != nil {
return return
@ -84,14 +75,12 @@ func (c *Client) mkcol(path string) (status int, err error) {
} }
func (c *Client) options(path string) (*http.Response, error) { func (c *Client) options(path string) (*http.Response, error) {
log.Printf("Client.options(%s)", path)
return c.req("OPTIONS", path, nil, func(rq *http.Request) { return c.req("OPTIONS", path, nil, func(rq *http.Request) {
rq.Header.Add("Depth", "0") rq.Header.Add("Depth", "0")
}) })
} }
func (c *Client) propfind(path string, self bool, body string, resp interface{}, parse func(resp interface{}) error) error { func (c *Client) propfind(path string, self bool, body string, resp interface{}, parse func(resp interface{}) error) error {
log.Printf("Client.propfind(%s)", path)
rs, err := c.req("PROPFIND", path, strings.NewReader(body), func(rq *http.Request) { rs, err := c.req("PROPFIND", path, strings.NewReader(body), func(rq *http.Request) {
if self { if self {
rq.Header.Add("Depth", "0") rq.Header.Add("Depth", "0")
@ -126,7 +115,6 @@ func (c *Client) doCopyMove(
r io.ReadCloser, r io.ReadCloser,
err error, err error,
) { ) {
log.Printf("Client.doCopyMove(%s, %s, %s)", method, oldpath, newpath)
rs, err := c.req(method, oldpath, nil, func(rq *http.Request) { rs, err := c.req(method, oldpath, nil, func(rq *http.Request) {
rq.Header.Add("Destination", PathEscape(Join(c.root, newpath))) rq.Header.Add("Destination", PathEscape(Join(c.root, newpath)))
if overwrite { if overwrite {
@ -144,7 +132,6 @@ func (c *Client) doCopyMove(
} }
func (c *Client) copymove(method string, oldpath string, newpath string, overwrite bool) (err error) { func (c *Client) copymove(method string, oldpath string, newpath string, overwrite bool) (err error) {
log.Printf("Client.copymove(%s, %s, %s)", method, oldpath, newpath)
s, data, err := c.doCopyMove(method, oldpath, newpath, overwrite) s, data, err := c.doCopyMove(method, oldpath, newpath, overwrite)
if err != nil { if err != nil {
return return
@ -174,7 +161,6 @@ func (c *Client) copymove(method string, oldpath string, newpath string, overwri
} }
func (c *Client) put(path string, stream io.Reader) (status int, err error) { func (c *Client) put(path string, stream io.Reader) (status int, err error) {
log.Printf("Client.put(%s)", path)
rs, err := c.req("PUT", path, stream, nil) rs, err := c.req("PUT", path, stream, nil)
if err != nil { if err != nil {
return return
@ -186,7 +172,6 @@ func (c *Client) put(path string, stream io.Reader) (status int, err error) {
} }
func (c *Client) createParentCollection(itemPath string) (err error) { func (c *Client) createParentCollection(itemPath string) (err error) {
log.Printf("Client.createParentCollection(%s)", itemPath)
parentPath := path.Dir(itemPath) parentPath := path.Dir(itemPath)
if parentPath == "." || parentPath == "/" { if parentPath == "." || parentPath == "/" {
return nil return nil