Try to fix the xml things.

This commit is contained in:
zicla
2019-04-17 22:26:13 +08:00
parent 522a4f903e
commit ba7b632046
7 changed files with 263 additions and 8 deletions

View File

@ -1,6 +1,18 @@
package rest
import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
)
/**
*
* WebDav协议文档
* https://tools.ietf.org/html/rfc4918
*
*/
//@Service
type DavService struct {
Bean
@ -17,3 +29,53 @@ func (this *DavService) Init() {
this.matterDao = b
}
}
//从request中读取深度
func (this *DavService) readDepth(request *http.Request) int {
depth := INFINITE_DEPTH
if hdr := request.Header.Get("Depth"); hdr != "" {
if hdr == "0" {
depth = 0
} else if hdr == "1" {
depth = 1
} else if hdr == "infinity" {
depth = INFINITE_DEPTH
} else {
panic("Depth格式错误")
}
}
return depth
}
//处理 方法
func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http.Request, subPath string) {
//获取请求者
user := this.checkUser(writer, request)
//读取希望访问的深度。
depth := this.readDepth(request)
//找寻请求的目录
matter := this.matterDao.checkByUserUuidAndPath(user.Uuid, subPath)
//TODO: 读取请求参数。按照用户的参数请求返回内容。
propfind := &Propfind{}
body, err := ioutil.ReadAll(request.Body)
this.PanicError(err)
//从xml中解析内容到struct
err = xml.Unmarshal(body, &propfind)
this.PanicError(err)
//从struct还原到xml
output, err := xml.MarshalIndent(propfind, " ", " ")
this.PanicError(err)
fmt.Println(string(output))
fmt.Printf("%v %v \n", depth, matter.Name)
}