Skip to content

Commit 09c621c

Browse files
committed
feat(serverHandler): add Authorization to Vary header
1 parent 227b3fc commit 09c621c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/serverHandler/vhostHandler.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func NewVhostHandler(
3636
errs = serverError.AppendError(errs, users.AddSha512(u[0], u[1]))
3737
}
3838

39+
// show/hide
3940
shows, err := wildcardToRegexp(p.Shows)
4041
errs = serverError.AppendError(errs, err)
4142
showDirs, err := wildcardToRegexp(p.ShowDirs)
@@ -53,18 +54,30 @@ func NewVhostHandler(
5354
return nil, errs
5455
}
5556

57+
// restrict access
5658
restrictAccessUrls := newRestrictAccesses(p.RestrictAccessUrls)
5759
restrictAccessDirs := newRestrictAccesses(p.RestrictAccessDirs)
5860
restrictAccess := hasRestrictAccess(p.GlobalRestrictAccess, restrictAccessUrls, restrictAccessDirs)
59-
pageVaryV1 := "Accept-Encoding"
60-
contentVaryV1 := ""
61+
62+
// `Vary` header
63+
pageVarys := make([]string, 0, 4)
64+
contentVarys := make([]string, 0, 3)
65+
pageVarys = append(pageVarys, "Accept-Encoding")
6166
if restrictAccess {
62-
pageVaryV1 += ", Referer, Origin"
63-
contentVaryV1 = "Referer, Origin"
67+
pageVarys = append(pageVarys, "Referer", "Origin")
68+
contentVarys = append(contentVarys, "Referer", "Origin")
69+
}
70+
if len(p.AuthUrls) > 0 || len(p.AuthDirs) > 0 {
71+
pageVarys = append(pageVarys, "Authorization")
72+
contentVarys = append(contentVarys, "Authorization")
6473
}
74+
75+
pageVaryV1 := strings.Join(pageVarys, ", ")
76+
contentVaryV1 := strings.Join(contentVarys, ", ")
6577
pageVary := strings.ToLower(pageVaryV1)
6678
contentVary := strings.ToLower(contentVaryV1)
6779

80+
// alias param
6881
ap := &aliasParam{
6982
users: *users,
7083
theme: theme,

0 commit comments

Comments
 (0)