mirror of
https://github.com/harivansh-afk/betterNAS.git
synced 2026-04-15 07:04:44 +00:00
Allow OPTIONS to bypass WebDAV auth for Finder discovery
macOS Finder sends an unauthenticated OPTIONS request before attempting auth. It needs to see the DAV: 1, 2 compliance header in the response to know the server supports WebDAV. Without it, Finder shows "problem connecting to the server" and never prompts for credentials. OPTIONS is a safe discovery method that exposes no data, so it can be served without auth.
This commit is contained in:
parent
18b6ac625f
commit
a6c74c2a39
1 changed files with 8 additions and 0 deletions
|
|
@ -169,6 +169,14 @@ func (a *app) handler() http.Handler {
|
||||||
|
|
||||||
func (a *app) requireDAVAuth(mount exportMount, next http.Handler) http.Handler {
|
func (a *app) requireDAVAuth(mount exportMount, next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// OPTIONS must bypass auth so the WebDAV handler can return its
|
||||||
|
// DAV: 1, 2 compliance header. macOS Finder sends an unauthenticated
|
||||||
|
// OPTIONS first and refuses to connect unless it sees that header.
|
||||||
|
if r.Method == http.MethodOptions {
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
username, password, ok := r.BasicAuth()
|
username, password, ok := r.BasicAuth()
|
||||||
if !ok {
|
if !ok {
|
||||||
writeDAVUnauthorized(w)
|
writeDAVUnauthorized(w)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue