Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend settings #86

Merged
merged 3 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions config/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ var (
)

type Backend struct {
ConnectTimeout string `hcl:"connect_timeout,optional"`
Name string `hcl:"name,label"`
Remain hcl.Body `hcl:",remain"`
RequestBodyLimit string `hcl:"request_body_limit,optional"`
TTFBTimeout string `hcl:"ttfb_timeout,optional"`
Timeout string `hcl:"timeout,optional"`
OpenAPI []*OpenAPI `hcl:"openapi,block"`
ConnectTimeout string `hcl:"connect_timeout,optional"`
DisableCertValidation bool `hcl:"disable_certificate_validation,optional"`
MaxConnections int `hcl:"max_connections,optional"`
Name string `hcl:"name,label"`
Remain hcl.Body `hcl:",remain"`
RequestBodyLimit string `hcl:"request_body_limit,optional"`
TTFBTimeout string `hcl:"ttfb_timeout,optional"`
Timeout string `hcl:"timeout,optional"`
OpenAPI []*OpenAPI `hcl:"openapi,block"`
}

func (b Backend) Body() hcl.Body {
Expand Down
9 changes: 5 additions & 4 deletions handler/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func (p *Proxy) getTransport(scheme, origin, hostname string) *http.Transport {
key := scheme + "|" + origin + "|" + hostname + "|" + p.optionsHash
transport, ok := transports.Load(key)
if !ok {
var tlsConf *tls.Config
tlsConf := &tls.Config{
InsecureSkipVerify: p.options.DisableCertValidation,
}
if origin != hostname {
tlsConf = &tls.Config{
ServerName: hostname,
}
tlsConf.ServerName = hostname
}

d := &net.Dialer{Timeout: p.options.ConnectTimeout}
Expand All @@ -159,6 +159,7 @@ func (p *Proxy) getTransport(scheme, origin, hostname string) *http.Transport {
return conn, nil
},
DisableCompression: true,
MaxConnsPerHost: p.options.MaxConnections,
ResponseHeaderTimeout: p.options.TTFBTimeout,
TLSClientConfig: tlsConf,
}
Expand Down
20 changes: 12 additions & 8 deletions handler/proxy_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type ProxyOptions struct {
Context hcl.Body
BackendName string
CORS *CORSOptions
DisableCertValidation bool
MaxConnections int
OpenAPI *OpenAPIValidatorOptions
RequestBodyLimit int64
}
Expand Down Expand Up @@ -48,14 +50,16 @@ func NewProxyOptions(conf *config.Backend, corsOpts *CORSOptions) (*ProxyOptions
}

return &ProxyOptions{
BackendName: conf.Name,
CORS: cors,
Context: conf.Remain,
ConnectTimeout: connTimeout,
OpenAPI: openAPIValidatorOptions,
RequestBodyLimit: bodyLimit,
TTFBTimeout: ttfbTimeout,
Timeout: timeout,
BackendName: conf.Name,
CORS: cors,
Context: conf.Remain,
ConnectTimeout: connTimeout,
DisableCertValidation: conf.DisableCertValidation,
MaxConnections: conf.MaxConnections,
OpenAPI: openAPIValidatorOptions,
RequestBodyLimit: bodyLimit,
TTFBTimeout: ttfbTimeout,
Timeout: timeout,
}, nil
}

Expand Down