@@ -6,36 +6,37 @@ import (
6
6
)
7
7
8
8
type profileConfig struct {
9
- pprof bool
10
- cmdline bool
11
- profile bool
12
- symbol bool
13
- trace bool
9
+ pprof bool
10
+ cmdline bool
11
+ profile bool
12
+ symbol bool
13
+ trace bool
14
+ enableTLS bool
14
15
}
15
16
16
17
// Option applies a configuration option to the given config.
17
18
type Option func (p * profileConfig )
18
19
19
20
func (p * profileConfig ) apply (options []Option ) {
20
- if len (options ) == 0 {
21
- // If no options are given, default to all
22
- p .pprof = true
23
- p .cmdline = true
24
- p .profile = true
25
- p .symbol = true
26
- p .trace = true
27
-
28
- return
29
- }
30
-
31
21
for _ , o := range options {
32
22
o (p )
33
23
}
34
24
}
35
25
26
+ func DisableTLS (p * profileConfig ) {
27
+ p .enableTLS = false
28
+ }
29
+
36
30
func defaultProfileConfig () * profileConfig {
37
31
// Initialize config
38
- return & profileConfig {}
32
+ return & profileConfig {
33
+ pprof : true ,
34
+ cmdline : true ,
35
+ profile : true ,
36
+ symbol : true ,
37
+ trace : true ,
38
+ enableTLS : true ,
39
+ }
39
40
}
40
41
41
42
// RegisterHandlers registers profile Handlers with the given ServeMux.
@@ -47,25 +48,25 @@ func RegisterHandlers(mux *http.ServeMux, options ...Option) {
47
48
config .apply (options )
48
49
49
50
if config .pprof {
50
- mux .Handle ("/debug/pprof/" , requireVerifiedClientCertificate (http .HandlerFunc (pprof .Index )))
51
+ mux .Handle ("/debug/pprof/" , pprofHandlerFunc (http .HandlerFunc (pprof .Index ), config . enableTLS ))
51
52
}
52
53
if config .cmdline {
53
- mux .Handle ("/debug/pprof/cmdline" , requireVerifiedClientCertificate (http .HandlerFunc (pprof .Cmdline )))
54
+ mux .Handle ("/debug/pprof/cmdline" , pprofHandlerFunc (http .HandlerFunc (pprof .Cmdline ), config . enableTLS ))
54
55
}
55
56
if config .profile {
56
- mux .Handle ("/debug/pprof/profile" , requireVerifiedClientCertificate (http .HandlerFunc (pprof .Profile )))
57
+ mux .Handle ("/debug/pprof/profile" , pprofHandlerFunc (http .HandlerFunc (pprof .Profile ), config . enableTLS ))
57
58
}
58
59
if config .symbol {
59
- mux .Handle ("/debug/pprof/symbol" , requireVerifiedClientCertificate (http .HandlerFunc (pprof .Symbol )))
60
+ mux .Handle ("/debug/pprof/symbol" , pprofHandlerFunc (http .HandlerFunc (pprof .Symbol ), config . enableTLS ))
60
61
}
61
62
if config .trace {
62
- mux .Handle ("/debug/pprof/trace" , requireVerifiedClientCertificate (http .HandlerFunc (pprof .Trace )))
63
+ mux .Handle ("/debug/pprof/trace" , pprofHandlerFunc (http .HandlerFunc (pprof .Trace ), config . enableTLS ))
63
64
}
64
65
}
65
66
66
- func requireVerifiedClientCertificate (h http.Handler ) http.Handler {
67
+ func pprofHandlerFunc (h http.Handler , enableTLS bool ) http.Handler {
67
68
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
68
- if r .TLS == nil || len (r .TLS .VerifiedChains ) == 0 {
69
+ if enableTLS && ( r .TLS == nil || len (r .TLS .VerifiedChains ) == 0 ) {
69
70
w .WriteHeader (http .StatusForbidden )
70
71
return
71
72
}
0 commit comments