Merge: + config: new setting 'http_proxy'

Close #458

* commit '2e054b673264bdb563abb6478979d00e76e52c8d':
  + config: new setting 'http_proxy'
This commit is contained in:
Simon Zolin 2020-03-16 14:58:21 +03:00
commit 88853b76d9
2 changed files with 10 additions and 0 deletions

View file

@ -51,6 +51,7 @@ type configuration struct {
BindHost string `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to
BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server
Users []User `yaml:"users"` // Users that can access HTTP server
ProxyURL string `yaml:"http_proxy"` // Proxy address for our HTTP client
Language string `yaml:"language"` // two-letter ISO 639-1 language code
RlimitNoFile uint `yaml:"rlimit_nofile"` // Maximum number of opened fd's per process (0: default)

View file

@ -9,6 +9,7 @@ import (
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"os/exec"
"os/signal"
@ -137,6 +138,7 @@ func run(args options) {
// Init some of the Context fields right away
Context.transport = &http.Transport{
DialContext: customDialContext,
Proxy: getHTTPProxy,
}
Context.client = &http.Client{
Timeout: time.Minute * 5,
@ -661,3 +663,10 @@ func customDialContext(ctx context.Context, network, addr string) (net.Conn, err
}
return nil, errorx.DecorateMany(fmt.Sprintf("couldn't dial to %s", addr), dialErrs...)
}
func getHTTPProxy(req *http.Request) (*url.URL, error) {
if len(config.ProxyURL) == 0 {
return nil, nil
}
return url.Parse(config.ProxyURL)
}