-
Notifications
You must be signed in to change notification settings - Fork 56
/
middleware.go
50 lines (39 loc) · 1.04 KB
/
middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package serverHandler
import (
"mjpclab.dev/ghfs/src/middleware"
"net/http"
)
func (h *aliasHandler) applyMiddlewares(mids []middleware.Middleware, w http.ResponseWriter, r *http.Request, data *responseData, fsPath string) (processed bool) {
if len(mids) == 0 {
return
}
context := &middleware.Context{
PrefixReqPath: data.prefixReqPath,
VhostReqPath: data.rawReqPath,
AliasReqPath: data.handlerReqPath,
AliasFsPath: fsPath,
AliasFsRoot: h.root,
WantJson: data.wantJson,
RestrictAccess: data.RestrictAccess,
AllowAccess: data.AllowAccess,
NeedAuth: data.NeedAuth,
AuthUserName: data.AuthUserName,
AuthSuccess: data.AuthSuccess,
CanUpload: &data.CanUpload,
CanMkdir: &data.CanMkdir,
CanDelete: &data.CanDelete,
CanArchive: &data.CanArchive,
Status: &data.Status,
Users: h.users,
Logger: h.logger,
}
for i := range mids {
result := mids[i](w, r, context)
if result == middleware.Outputted {
return true
} else if result == middleware.SkipRests {
break
}
}
return false
}