Keep reading the webdav codes.
This commit is contained in:
parent
8dc00d36eb
commit
522a4f903e
@ -512,7 +512,7 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
|
|||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
ctx := request.Context()
|
ctx := request.Context()
|
||||||
fi, err := this.FileSystem.Stat(ctx, reqPath)
|
fileInfo, err := this.FileSystem.Stat(ctx, reqPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return http.StatusNotFound, err
|
return http.StatusNotFound, err
|
||||||
@ -532,7 +532,7 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
|
|||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
|
||||||
mw := multistatusWriter{w: writer}
|
multiStatusWriter := multistatusWriter{w: writer}
|
||||||
|
|
||||||
walkFn := func(reqPath string, info os.FileInfo, err error) error {
|
walkFn := func(reqPath string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
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",
|
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())
|
reqPath, info.Name(), info.IsDir(), info.Mode(), info.ModTime(), info.Size())
|
||||||
var pstats []Propstat
|
var propstats []Propstat
|
||||||
if pf.Propname != nil {
|
if pf.Propname != nil {
|
||||||
pnames, err := propnames(ctx, this.FileSystem, this.LockSystem, reqPath)
|
pnames, err := propnames(ctx, this.FileSystem, this.LockSystem, reqPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -551,11 +551,11 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
|
|||||||
for _, xmlname := range pnames {
|
for _, xmlname := range pnames {
|
||||||
pstat.Props = append(pstat.Props, Property{XMLName: xmlname})
|
pstat.Props = append(pstat.Props, Property{XMLName: xmlname})
|
||||||
}
|
}
|
||||||
pstats = append(pstats, pstat)
|
propstats = append(propstats, pstat)
|
||||||
} else if pf.Allprop != nil {
|
} 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 {
|
} 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -564,11 +564,11 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
|
|||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
href += "/"
|
href += "/"
|
||||||
}
|
}
|
||||||
return mw.write(makePropstatResponse(href, pstats))
|
return multiStatusWriter.write(makePropstatResponse(href, propstats))
|
||||||
}
|
}
|
||||||
|
|
||||||
walkErr := walkFS(ctx, this.FileSystem, depth, reqPath, fi, walkFn)
|
walkErr := walkFS(ctx, this.FileSystem, depth, reqPath, fileInfo, walkFn)
|
||||||
closeErr := mw.close()
|
closeErr := multiStatusWriter.close()
|
||||||
if walkErr != nil {
|
if walkErr != nil {
|
||||||
return http.StatusInternalServerError, walkErr
|
return http.StatusInternalServerError, walkErr
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,7 @@ type multistatusWriter struct {
|
|||||||
// first, valid response to be written, Write prepends the XML representation
|
// 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
|
// of r with a multistatus tag. Callers must call close after the last response
|
||||||
// has been written.
|
// has been written.
|
||||||
func (w *multistatusWriter) write(r *response) error {
|
func (this *multistatusWriter) write(r *response) error {
|
||||||
switch len(r.Href) {
|
switch len(r.Href) {
|
||||||
case 0:
|
case 0:
|
||||||
return errInvalidResponse
|
return errInvalidResponse
|
||||||
@ -340,28 +340,28 @@ func (w *multistatusWriter) write(r *response) error {
|
|||||||
return errInvalidResponse
|
return errInvalidResponse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := w.writeHeader()
|
err := this.writeHeader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return w.enc.Encode(r)
|
return this.enc.Encode(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeHeader writes a XML multistatus start element on w's underlying
|
// writeHeader writes a XML multistatus start element on w's underlying
|
||||||
// http.ResponseWriter and returns the result of the write operation.
|
// http.ResponseWriter and returns the result of the write operation.
|
||||||
// After the first write attempt, writeHeader becomes a no-op.
|
// After the first write attempt, writeHeader becomes a no-op.
|
||||||
func (w *multistatusWriter) writeHeader() error {
|
func (this *multistatusWriter) writeHeader() error {
|
||||||
if w.enc != nil {
|
if this.enc != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
w.w.Header().Add("Content-Type", "text/xml; charset=utf-8")
|
this.w.Header().Add("Content-Type", "text/xml; charset=utf-8")
|
||||||
w.w.WriteHeader(StatusMulti)
|
this.w.WriteHeader(StatusMulti)
|
||||||
_, err := fmt.Fprintf(w.w, `<?xml version="1.0" encoding="UTF-8"?>`)
|
_, err := fmt.Fprintf(this.w, `<?xml version="1.0" encoding="UTF-8"?>`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.enc = ixml.NewEncoder(w.w)
|
this.enc = ixml.NewEncoder(this.w)
|
||||||
return w.enc.EncodeToken(ixml.StartElement{
|
return this.enc.EncodeToken(ixml.StartElement{
|
||||||
Name: ixml.Name{
|
Name: ixml.Name{
|
||||||
Space: "DAV:",
|
Space: "DAV:",
|
||||||
Local: "multistatus",
|
Local: "multistatus",
|
||||||
@ -377,16 +377,16 @@ func (w *multistatusWriter) writeHeader() error {
|
|||||||
// an error if the multistatus response could not be completed. If both the
|
// 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
|
// return value and field enc of w are nil, then no multistatus response has
|
||||||
// been written.
|
// been written.
|
||||||
func (w *multistatusWriter) close() error {
|
func (this *multistatusWriter) close() error {
|
||||||
if w.enc == nil {
|
if this.enc == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var end []ixml.Token
|
var end []ixml.Token
|
||||||
if w.responseDescription != "" {
|
if this.responseDescription != "" {
|
||||||
name := ixml.Name{Space: "DAV:", Local: "responsedescription"}
|
name := ixml.Name{Space: "DAV:", Local: "responsedescription"}
|
||||||
end = append(end,
|
end = append(end,
|
||||||
ixml.StartElement{Name: name},
|
ixml.StartElement{Name: name},
|
||||||
ixml.CharData(w.responseDescription),
|
ixml.CharData(this.responseDescription),
|
||||||
ixml.EndElement{Name: name},
|
ixml.EndElement{Name: name},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -394,12 +394,12 @@ func (w *multistatusWriter) close() error {
|
|||||||
Name: ixml.Name{Space: "DAV:", Local: "multistatus"},
|
Name: ixml.Name{Space: "DAV:", Local: "multistatus"},
|
||||||
})
|
})
|
||||||
for _, t := range end {
|
for _, t := range end {
|
||||||
err := w.enc.EncodeToken(t)
|
err := this.enc.EncodeToken(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return w.enc.Flush()
|
return this.enc.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
var xmlLangName = ixml.Name{Space: "http://www.w3.org/XML/1998/namespace", Local: "lang"}
|
var xmlLangName = ixml.Name{Space: "http://www.w3.org/XML/1998/namespace", Local: "lang"}
|
||||||
|
Loading…
Reference in New Issue
Block a user