refactor(security): 将安全头辅助函数改为私有
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7f4c8f547c
commit
bab0228e1d
@ -288,11 +288,11 @@ func (sh *HeadersMiddleware) GetConfig() *config.SecurityHeaders {
|
||||
return sh.config
|
||||
}
|
||||
|
||||
// DefaultSecurityHeaders 返回安全的安全头默认配置。
|
||||
// defaultSecurityHeaders 返回安全的安全头默认配置。
|
||||
//
|
||||
// 返回值:
|
||||
// - *config.SecurityHeaders: 包含安全默认值的配置对象
|
||||
func DefaultSecurityHeaders() *config.SecurityHeaders {
|
||||
func defaultSecurityHeaders() *config.SecurityHeaders {
|
||||
return &config.SecurityHeaders{
|
||||
XFrameOptions: "DENY",
|
||||
XContentTypeOptions: "nosniff",
|
||||
@ -300,13 +300,13 @@ func DefaultSecurityHeaders() *config.SecurityHeaders {
|
||||
}
|
||||
}
|
||||
|
||||
// StrictSecurityHeaders 返回严格模式的安全头配置。
|
||||
// strictSecurityHeaders 返回严格模式的安全头配置。
|
||||
//
|
||||
// 适用于高安全要求的应用场景,包含严格的 CSP 和权限策略。
|
||||
//
|
||||
// 返回值:
|
||||
// - *config.SecurityHeaders: 包含严格安全值的配置对象
|
||||
func StrictSecurityHeaders() *config.SecurityHeaders {
|
||||
func strictSecurityHeaders() *config.SecurityHeaders {
|
||||
return &config.SecurityHeaders{
|
||||
XFrameOptions: "DENY",
|
||||
XContentTypeOptions: "nosniff",
|
||||
@ -316,13 +316,13 @@ func StrictSecurityHeaders() *config.SecurityHeaders {
|
||||
}
|
||||
}
|
||||
|
||||
// DevelopmentSecurityHeaders 返回开发环境使用的宽松安全头配置。
|
||||
// developmentSecurityHeaders 返回开发环境使用的宽松安全头配置。
|
||||
//
|
||||
// 警告:请勿在生产环境使用此配置,安全性较低。
|
||||
//
|
||||
// 返回值:
|
||||
// - *config.SecurityHeaders: 包含宽松安全值的配置对象
|
||||
func DevelopmentSecurityHeaders() *config.SecurityHeaders {
|
||||
func developmentSecurityHeaders() *config.SecurityHeaders {
|
||||
return &config.SecurityHeaders{
|
||||
XFrameOptions: "SAMEORIGIN",
|
||||
XContentTypeOptions: "nosniff",
|
||||
|
||||
@ -182,7 +182,7 @@ func TestUpdateConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDefaultSecurityHeaders(t *testing.T) {
|
||||
cfg := DefaultSecurityHeaders()
|
||||
cfg := defaultSecurityHeaders()
|
||||
|
||||
if cfg.XFrameOptions != "DENY" {
|
||||
t.Errorf("Expected default X-Frame-Options 'DENY', got %s", cfg.XFrameOptions)
|
||||
@ -193,7 +193,7 @@ func TestDefaultSecurityHeaders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStrictSecurityHeaders(t *testing.T) {
|
||||
cfg := StrictSecurityHeaders()
|
||||
cfg := strictSecurityHeaders()
|
||||
|
||||
if cfg.XFrameOptions != "DENY" {
|
||||
t.Errorf("Expected X-Frame-Options 'DENY', got %s", cfg.XFrameOptions)
|
||||
@ -207,7 +207,7 @@ func TestStrictSecurityHeaders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDevelopmentSecurityHeaders(t *testing.T) {
|
||||
cfg := DevelopmentSecurityHeaders()
|
||||
cfg := developmentSecurityHeaders()
|
||||
|
||||
if cfg.XFrameOptions != "SAMEORIGIN" {
|
||||
t.Errorf("Expected X-Frame-Options 'SAMEORIGIN' for dev, got %s", cfg.XFrameOptions)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user