+ config: new setting 'http_proxy'
This commit is contained in:
parent
b600d7b09d
commit
2e054b6732
@ -51,6 +51,7 @@ type configuration struct {
|
|||||||
BindHost string `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to
|
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
|
BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server
|
||||||
Users []User `yaml:"users"` // Users that can access 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
|
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)
|
RlimitNoFile uint `yaml:"rlimit_nofile"` // Maximum number of opened fd's per process (0: default)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -137,6 +138,7 @@ func run(args options) {
|
|||||||
// Init some of the Context fields right away
|
// Init some of the Context fields right away
|
||||||
Context.transport = &http.Transport{
|
Context.transport = &http.Transport{
|
||||||
DialContext: customDialContext,
|
DialContext: customDialContext,
|
||||||
|
Proxy: getHTTPProxy,
|
||||||
}
|
}
|
||||||
Context.client = &http.Client{
|
Context.client = &http.Client{
|
||||||
Timeout: time.Minute * 5,
|
Timeout: time.Minute * 5,
|
||||||
@ -658,3 +660,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...)
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user