-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
drive: rewrite LOCK paths #12137
drive: rewrite LOCK paths #12137
Conversation
677b021
to
32d58d2
Compare
@@ -93,8 +93,17 @@ var cacheInvalidatingMethods = map[string]bool{ | |||
|
|||
// ServeHTTP implements http.Handler. | |||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
if r.Method == "PROPFIND" { | |||
h.handlePROPFIND(w, r) | |||
pathComponents := shared.CleanAndSplit(r.URL.Path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by: do this only once, then pass results to the methods that need them.
af3d20d
to
6f94023
Compare
@@ -0,0 +1,112 @@ | |||
// Copyright (c) Tailscale Inc & AUTHORS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file replaces propfind.go with all rewriting logic, including for PROPFIND and LOCK.
share11 = `sha re$%11` | ||
share12 = `_sha re$%12` | ||
file111 = `fi le$%111.txt` | ||
remote1 = `rem ote$%<>1` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by: we weren't properly escaping paths for inclusion in XML, this tests for that.
h.delegate(mpl, pathComponents[mpl-1:], bw, r) | ||
|
||
// Fixup paths to add the requested path as a prefix, escaped for inclusion in XML. | ||
pp := shared.EscapeForXML(shared.Join(pathComponents[0:mpl]...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by: properly escape paths for inclusion in XML.
case "1": | ||
return 1 | ||
case "infinity": | ||
return math.MaxInt16 // a really large number, but not infinity (avoids wrapping when we do arithmetic with this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by: this used to be MaxInt, which wrapped when we added +1
to it.
6f94023
to
e5bdce6
Compare
) | ||
|
||
var ( | ||
responseHrefRegex = regexp.MustCompile(`(?s)(<D:(response|lockroot)>)<D:href>/?([^<]*)/?</D:href>`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<D:href> appears in various contexts, but we're only interested when it's used with <D:response>
or <D:lockroot>
.
e5bdce6
to
b2a2f76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I don't think I know enough about WebDAV to really review for accuracy, but the restructure of code lgtm.
http.Error(w, "locking of top level directories is not allowed", http.StatusMethodNotAllowed) | ||
} | ||
|
||
func shouldDelegateToChild(r *http.Request, pathComponents []string, mpl int) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe add some docs to this function? a little confusing to decipher for someone new
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
return bw.buf.Write(p) | ||
} | ||
|
||
func rewriteIfHeader(r *http.Request, pathComponents []string, mpl int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: docs for this one too pls!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Fixes #12097 Signed-off-by: Percy Wegmann <[email protected]>
b2a2f76
to
659cbbb
Compare
Thanks for the review @soniaappasamy |
Fixes #12097
Just like we rewrite paths for
PROPFIND
responses to reflect the unified filesystem structure of<tailnet>/<peer>/<share>/<file>
, we also have to rewrite paths used inLOCK
requests and responses.