Skip to content

Commit ea240c6

Browse files
committed
feat(serverHandler): save auth username to response data
1 parent 1a51bcd commit ea240c6

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/serverHandler/auth.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package serverHandler
22

33
import "net/http"
44

5-
func (h *handler) auth(w http.ResponseWriter, r *http.Request) (success bool) {
5+
func (h *handler) auth(w http.ResponseWriter, r *http.Request, data *responseData) (success bool) {
66
header := w.Header()
77
header.Set("WWW-Authenticate", "Basic realm=\""+r.URL.Path+"\"")
88

@@ -11,7 +11,9 @@ func (h *handler) auth(w http.ResponseWriter, r *http.Request) (success bool) {
1111
success = h.users.Auth(username, password)
1212
}
1313

14-
if !success {
14+
if success {
15+
data.AuthUserName = username
16+
} else {
1517
w.WriteHeader(http.StatusUnauthorized)
1618
}
1719

src/serverHandler/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
9393
defer file.Close()
9494
}
9595

96-
if data.NeedAuth && !h.auth(w, r) {
96+
if data.NeedAuth && !h.auth(w, r, data) {
9797
return
9898
}
9999

src/serverHandler/responseData.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type responseData struct {
5252
CanArchive bool
5353
CanCors bool
5454
NeedAuth bool
55+
AuthUserName string
5556

5657
IsDownload bool
5758
IsUpload bool

0 commit comments

Comments
 (0)