Skip to content

Commit dcef53a

Browse files
authored
Do not use global variable to store default options (goadesign#1369)
So that the defaults cannot be modified.
1 parent 872d897 commit dcef53a

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

middleware/gzip/middleware.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,6 @@ type (
109109
}
110110
)
111111

112-
var defaultOptions = options{
113-
minSize: 256,
114-
contentTypes: defaultContentTypes,
115-
}
116-
117-
func init() {
118-
defaultOptions.statusCodes = make(map[int]struct{}, len(defaultStatusCodes))
119-
for _, v := range defaultStatusCodes {
120-
defaultOptions.statusCodes[v] = struct{}{}
121-
}
122-
}
123-
124112
// defaultContentTypes is the default list of content types for which
125113
// a Handler considers gzip compression. This list originates from the
126114
// file compression.conf within the Apache configuration found at
@@ -241,7 +229,14 @@ func MinSize(n int) Option {
241229
// headers. If the Content-Type is not set, it will be set by calling
242230
// http.DetectContentType on the data being written.
243231
func Middleware(level int, o ...Option) goa.Middleware {
244-
opts := defaultOptions
232+
opts := options{
233+
minSize: 256,
234+
contentTypes: defaultContentTypes,
235+
}
236+
opts.statusCodes = make(map[int]struct{}, len(defaultStatusCodes))
237+
for _, v := range defaultStatusCodes {
238+
opts.statusCodes[v] = struct{}{}
239+
}
245240
for _, opt := range o {
246241
err := opt(&opts)
247242
if err != nil {

0 commit comments

Comments
 (0)