Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add WebDAV support(#1610) #2173

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ const (
PROPFIND = "PROPFIND"
// REPORT Method can be used to get information about a resource, see rfc 3253
REPORT = "REPORT"
// RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)
// https://tools.ietf.org/html/rfc4918
MKCOL = "MKCOL"
COPY = "COPY"
MOVE = "MOVE"
LOCK = "LOCK"
UNLOCK = "UNLOCK"
PROPPATCH = "PROPPATCH"
)

// Headers
Expand Down Expand Up @@ -274,6 +282,12 @@ var (
http.MethodPut,
http.MethodTrace,
REPORT,
MKCOL,
COPY,
MOVE,
LOCK,
UNLOCK,
PROPPATCH,
}
)

Expand Down
57 changes: 56 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ type (
put HandlerFunc
trace HandlerFunc
report HandlerFunc
mkcol HandlerFunc
copy HandlerFunc
move HandlerFunc
lock HandlerFunc
unlock HandlerFunc
proppatch HandlerFunc
allowHeader string
}
)
Expand All @@ -67,7 +73,13 @@ func (m *methodHandler) isHandler() bool {
m.propfind != nil ||
m.put != nil ||
m.trace != nil ||
m.report != nil
m.report != nil ||
m.mkcol != nil ||
m.copy != nil ||
m.move != nil ||
m.lock != nil ||
m.unlock != nil ||
m.proppatch != nil
}

func (m *methodHandler) updateAllowHeader() {
Expand Down Expand Up @@ -112,6 +124,25 @@ func (m *methodHandler) updateAllowHeader() {
if m.report != nil {
buf.WriteString(", REPORT")
}
if m.mkcol != nil {
buf.WriteString(", MKCOL")
}
if m.copy != nil {
buf.WriteString(", COPY")
}
if m.move != nil {
buf.WriteString(", MOVE")
}
if m.lock != nil {
buf.WriteString(", LOCK")
}
if m.unlock != nil {
buf.WriteString(", UNLOCK")
}
if m.proppatch != nil {
buf.WriteString(", PROPPATCH")
}

m.allowHeader = buf.String()
}

Expand Down Expand Up @@ -371,6 +402,18 @@ func (n *node) addHandler(method string, h HandlerFunc) {
n.methodHandler.trace = h
case REPORT:
n.methodHandler.report = h
case MKCOL:
n.methodHandler.mkcol = h
case COPY:
n.methodHandler.copy = h
case MOVE:
n.methodHandler.move = h
case LOCK:
n.methodHandler.lock = h
case UNLOCK:
n.methodHandler.unlock = h
case PROPPATCH:
n.methodHandler.proppatch = h
}

n.methodHandler.updateAllowHeader()
Expand Down Expand Up @@ -405,6 +448,18 @@ func (n *node) findHandler(method string) HandlerFunc {
return n.methodHandler.trace
case REPORT:
return n.methodHandler.report
case MKCOL:
return n.methodHandler.mkcol
case COPY:
return n.methodHandler.copy
case MOVE:
return n.methodHandler.move
case LOCK:
return n.methodHandler.lock
case UNLOCK:
return n.methodHandler.unlock
case PROPPATCH:
return n.methodHandler.proppatch
default:
return nil
}
Expand Down