Skip to content

Commit a64dc5d

Browse files
authored
add disable virtual host (#43)
1 parent b93bc40 commit a64dc5d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

reverseproxy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ func (p *ReverseProxy) ServeHTTP(ctx *fasthttp.RequestCtx) {
138138
debugF(p.opt.debug, p.opt.logger, "rev request headers to proxy, addr = %s, headers = %s", c.Addr, req.Header.String())
139139

140140
// assign the host to support virtual hosting, aka shared web hosting (one IP, multiple domains)
141-
req.SetHost(c.Addr)
141+
if !p.opt.disableVirtualHost {
142+
req.SetHost(c.Addr)
143+
}
142144

143145
// execute the request and rev response with timeout
144146
if err := p.doWithTimeout(c, req, res); err != nil {

reverseproxy_option.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type buildOption struct {
3737
// disablePathNormalizing disable path normalizing.
3838
disablePathNormalizing bool
3939

40+
// disableVirtualHost disable virtual host.
41+
disableVirtualHost bool
42+
4043
// maxConnDuration of hostClient
4144
maxConnDuration time.Duration
4245
}
@@ -51,6 +54,7 @@ func defaultBuildOption() *buildOption {
5154
tlsConfig: nil,
5255
timeout: 0,
5356
disablePathNormalizing: false,
57+
disableVirtualHost: false,
5458
maxConnDuration: 0,
5559
}
5660
}
@@ -124,6 +128,13 @@ func WithDisablePathNormalizing(isDisablePathNormalizing bool) Option {
124128
})
125129
}
126130

131+
// WithDisableVirtualHost sets whether disable virtual host.
132+
func WithDisableVirtualHost(isDisableVirtualHost bool) Option {
133+
return newFuncBuildOption(func(o *buildOption) {
134+
o.disableVirtualHost = isDisableVirtualHost
135+
})
136+
}
137+
127138
// WithMaxConnDuration sets maxConnDuration of hostClient, which
128139
// means keep-alive connections are closed after this duration.
129140
func WithMaxConnDuration(d time.Duration) Option {

0 commit comments

Comments
 (0)