Problem described in #20 is in using of TeeReader.
Our current code for TeeReader is:
func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (req *http.Response, err error) {
// Tee the body, because if authorization fails we will need to read from it again.
var ba bytes.Buffer
bb := io.TeeReader(body, &ba)
and as you see when we creating new http.NewRequest() we send &ba as body:
But in documentation to TeeReader you can see, that data should be read from bb first (because TeeReader writes data to Writer only when this data is read from returned Reader, so in line 16 our Writer is always empty).
I go further and trying to just replace &ba to bb in line 16. But in this case I face with new problem: application begin panic with message runtime error: invalid memory address or nil pointer dereference, because in some cases our TeeReader wraps nil, because body from arguments to c.req() is nil (for example when c.req() was called by c.mkcol(), c.options() and other methods which set body to nil).
This is quickfix, so I sure that code can be more elegant, but this pull-request allow to restore functionality of gowebdav project while this bug will be fixed in more elegant way.
Problem described in #20 is in using of
TeeReader
. Our current code forTeeReader
is:and as you see when we creating new
http.NewRequest()
we send&ba
asbody
:But in documentation to
TeeReader
you can see, that data should be read frombb
first (becauseTeeReader
writes data toWriter
only when this data is read from returnedReader
, so in line 16 ourWriter
is always empty).I go further and trying to just replace
&ba
tobb
in line 16. But in this case I face with new problem: application beginpanic
with messageruntime error: invalid memory address or nil pointer dereference
, because in some cases ourTeeReader
wrapsnil
, becausebody
from arguments toc.req()
isnil
(for example whenc.req()
was called byc.mkcol()
,c.options()
and other methods which setbody
tonil
).This is quickfix, so I sure that code can be more elegant, but this pull-request allow to restore functionality of
gowebdav
project while this bug will be fixed in more elegant way.