Keep reading the webdav codes.

This commit is contained in:
zicla 2019-04-14 03:41:04 +08:00
parent 8dc00d36eb
commit 522a4f903e
2 changed files with 25 additions and 25 deletions

View File

@ -512,7 +512,7 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
return status, err
}
ctx := request.Context()
fi, err := this.FileSystem.Stat(ctx, reqPath)
fileInfo, err := this.FileSystem.Stat(ctx, reqPath)
if err != nil {
if os.IsNotExist(err) {
return http.StatusNotFound, err
@ -532,7 +532,7 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
return status, err
}
mw := multistatusWriter{w: writer}
multiStatusWriter := multistatusWriter{w: writer}
walkFn := func(reqPath string, info os.FileInfo, err error) error {
if err != nil {
@ -541,7 +541,7 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
fmt.Printf("浏览:%s {name=%s,IsDir=%v,Mode=%v,ModTime=%v,Size=%v}\n",
reqPath, info.Name(), info.IsDir(), info.Mode(), info.ModTime(), info.Size())
var pstats []Propstat
var propstats []Propstat
if pf.Propname != nil {
pnames, err := propnames(ctx, this.FileSystem, this.LockSystem, reqPath)
if err != nil {
@ -551,11 +551,11 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
for _, xmlname := range pnames {
pstat.Props = append(pstat.Props, Property{XMLName: xmlname})
}
pstats = append(pstats, pstat)
propstats = append(propstats, pstat)
} else if pf.Allprop != nil {
pstats, err = allprop(ctx, this.FileSystem, this.LockSystem, reqPath, pf.Prop)
propstats, err = allprop(ctx, this.FileSystem, this.LockSystem, reqPath, pf.Prop)
} else {
pstats, err = props(ctx, this.FileSystem, this.LockSystem, reqPath, pf.Prop)
propstats, err = props(ctx, this.FileSystem, this.LockSystem, reqPath, pf.Prop)
}
if err != nil {
return err
@ -564,11 +564,11 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
if info.IsDir() {
href += "/"
}
return mw.write(makePropstatResponse(href, pstats))
return multiStatusWriter.write(makePropstatResponse(href, propstats))
}
walkErr := walkFS(ctx, this.FileSystem, depth, reqPath, fi, walkFn)
closeErr := mw.close()
walkErr := walkFS(ctx, this.FileSystem, depth, reqPath, fileInfo, walkFn)
closeErr := multiStatusWriter.close()
if walkErr != nil {
return http.StatusInternalServerError, walkErr
}

View File

@ -327,7 +327,7 @@ type multistatusWriter struct {
// first, valid response to be written, Write prepends the XML representation
// of r with a multistatus tag. Callers must call close after the last response
// has been written.
func (w *multistatusWriter) write(r *response) error {
func (this *multistatusWriter) write(r *response) error {
switch len(r.Href) {
case 0:
return errInvalidResponse
@ -340,28 +340,28 @@ func (w *multistatusWriter) write(r *response) error {
return errInvalidResponse
}
}
err := w.writeHeader()
err := this.writeHeader()
if err != nil {
return err
}
return w.enc.Encode(r)
return this.enc.Encode(r)
}
// writeHeader writes a XML multistatus start element on w's underlying
// http.ResponseWriter and returns the result of the write operation.
// After the first write attempt, writeHeader becomes a no-op.
func (w *multistatusWriter) writeHeader() error {
if w.enc != nil {
func (this *multistatusWriter) writeHeader() error {
if this.enc != nil {
return nil
}
w.w.Header().Add("Content-Type", "text/xml; charset=utf-8")
w.w.WriteHeader(StatusMulti)
_, err := fmt.Fprintf(w.w, `<?xml version="1.0" encoding="UTF-8"?>`)
this.w.Header().Add("Content-Type", "text/xml; charset=utf-8")
this.w.WriteHeader(StatusMulti)
_, err := fmt.Fprintf(this.w, `<?xml version="1.0" encoding="UTF-8"?>`)
if err != nil {
return err
}
w.enc = ixml.NewEncoder(w.w)
return w.enc.EncodeToken(ixml.StartElement{
this.enc = ixml.NewEncoder(this.w)
return this.enc.EncodeToken(ixml.StartElement{
Name: ixml.Name{
Space: "DAV:",
Local: "multistatus",
@ -377,16 +377,16 @@ func (w *multistatusWriter) writeHeader() error {
// an error if the multistatus response could not be completed. If both the
// return value and field enc of w are nil, then no multistatus response has
// been written.
func (w *multistatusWriter) close() error {
if w.enc == nil {
func (this *multistatusWriter) close() error {
if this.enc == nil {
return nil
}
var end []ixml.Token
if w.responseDescription != "" {
if this.responseDescription != "" {
name := ixml.Name{Space: "DAV:", Local: "responsedescription"}
end = append(end,
ixml.StartElement{Name: name},
ixml.CharData(w.responseDescription),
ixml.CharData(this.responseDescription),
ixml.EndElement{Name: name},
)
}
@ -394,12 +394,12 @@ func (w *multistatusWriter) close() error {
Name: ixml.Name{Space: "DAV:", Local: "multistatus"},
})
for _, t := range end {
err := w.enc.EncodeToken(t)
err := this.enc.EncodeToken(t)
if err != nil {
return err
}
}
return w.enc.Flush()
return this.enc.Flush()
}
var xmlLangName = ixml.Name{Space: "http://www.w3.org/XML/1998/namespace", Local: "lang"}