Skip to content

Commit f6e7c81

Browse files
committed
docs: refine secure.go configuration handling
- Add comments to the `Config` struct in `secure.go` - Insert a new line in `secure_test.go` without additional content - Remove an empty line from `secure_test.go` Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent e944b63 commit f6e7c81

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (p *policy) loadConfig(config Config) {
6767
if config.STSIncludeSubdomains {
6868
stsSub = "; includeSubdomains"
6969
}
70-
if config.STSPreload {
70+
if config.STSPreload {
7171
stsSub = "; preload"
7272
}
7373
// TODO

secure.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "github.com/gin-gonic/gin"
55
// Config is a struct for specifying configuration options for the secure.
66
type Config struct {
77
// AllowedHosts is a list of fully qualified domain names that are allowed.
8-
//Default is empty list, which allows any and all host names.
8+
// Default is empty list, which allows any and all host names.
99
AllowedHosts []string
1010
// If SSLRedirect is set to true, then only allow https requests.
1111
// Default is false.
@@ -22,11 +22,11 @@ type Config struct {
2222
// If STSIncludeSubdomains is set to true, the `includeSubdomains` will
2323
// be appended to the Strict-Transport-Security header. Default is false.
2424
STSIncludeSubdomains bool
25-
// If STSPreload is set to true, the `; preload` will be appended to the
26-
// Strict-Transport-Security header. Default is false.
27-
// Note that removal is non-trivial and enabling this means you need to
28-
// support https long-term. See https://hstspreload.org/ for more info.
29-
STSPreload bool
25+
// If STSPreload is set to true, the `; preload` will be appended to the
26+
// Strict-Transport-Security header. Default is false.
27+
// Note that removal is non-trivial and enabling this means you need to
28+
// support https long-term. See https://hstspreload.org/ for more info.
29+
STSPreload bool
3030
// If FrameDeny is set to true, adds the X-Frame-Options header with
3131
// the value of `DENY`. Default is false.
3232
FrameDeny bool
@@ -64,15 +64,17 @@ type Config struct {
6464

6565
// DefaultConfig returns a Configuration with strict security settings.
6666
// ```
67-
// SSLRedirect: true
68-
// IsDevelopment: false
69-
// STSSeconds: 315360000
70-
// STSIncludeSubdomains: true
71-
// FrameDeny: true
72-
// ContentTypeNosniff: true
73-
// BrowserXssFilter: true
74-
// ContentSecurityPolicy: "default-src 'self'"
75-
// SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
67+
//
68+
// SSLRedirect: true
69+
// IsDevelopment: false
70+
// STSSeconds: 315360000
71+
// STSIncludeSubdomains: true
72+
// FrameDeny: true
73+
// ContentTypeNosniff: true
74+
// BrowserXssFilter: true
75+
// ContentSecurityPolicy: "default-src 'self'"
76+
// SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
77+
//
7678
// ```
7779
func DefaultConfig() Config {
7880
return Config{

secure_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func TestBadMultipleAllowHosts(t *testing.T) {
110110

111111
assert.Equal(t, http.StatusForbidden, w.Code)
112112
}
113+
113114
func TestAllowHostsInDevMode(t *testing.T) {
114115
router := newServer(Config{
115116
AllowedHosts: []string{"www.example.com", "sub.example.com"},
@@ -122,7 +123,6 @@ func TestAllowHostsInDevMode(t *testing.T) {
122123
}
123124

124125
func TestBadHostHandler(t *testing.T) {
125-
126126
badHandler := func(c *gin.Context) {
127127
c.String(http.StatusInternalServerError, "BadHost")
128128
c.Abort()
@@ -175,7 +175,7 @@ func TestBasicSSL(t *testing.T) {
175175

176176
func TestDontRedirectIPV4Hostnames(t *testing.T) {
177177
router := newServer(Config{
178-
SSLRedirect: true,
178+
SSLRedirect: true,
179179
DontRedirectIPV4Hostnames: true,
180180
})
181181

0 commit comments

Comments
 (0)