Skip to content

Commit ba2d47c

Browse files
authored
Merge pull request #37 from hankji/master
add MaxConnDuration option for hostClient
2 parents f04a704 + d9e4de9 commit ba2d47c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

reverseproxy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (p *ReverseProxy) init() error {
8484
IsTLS: p.opt.tlsConfig != nil,
8585
TLSConfig: p.opt.tlsConfig,
8686
DisablePathNormalizing: p.opt.disablePathNormalizing,
87+
MaxConnDuration: p.opt.maxConnDuration,
8788
}
8889
p.clients = append(p.clients, client)
8990
return nil

reverseproxy_option.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type buildOption struct {
3636

3737
// disablePathNormalizing disable path normalizing.
3838
disablePathNormalizing bool
39+
40+
// maxConnDuration of hostClient
41+
maxConnDuration time.Duration
3942
}
4043

4144
func defaultBuildOption() *buildOption {
@@ -48,6 +51,7 @@ func defaultBuildOption() *buildOption {
4851
tlsConfig: nil,
4952
timeout: 0,
5053
disablePathNormalizing: false,
54+
maxConnDuration: 0,
5155
}
5256
}
5357

@@ -119,3 +123,11 @@ func WithDisablePathNormalizing(isDisablePathNormalizing bool) Option {
119123
o.disablePathNormalizing = isDisablePathNormalizing
120124
})
121125
}
126+
127+
// WithMaxConnDuration sets maxConnDuration of hostClient, which
128+
// means keep-alive connections are closed after this duration.
129+
func WithMaxConnDuration(d time.Duration) Option {
130+
return newFuncBuildOption(func(o *buildOption) {
131+
o.maxConnDuration = d
132+
})
133+
}

0 commit comments

Comments
 (0)