mirror of https://github.com/0xERR0R/blocky.git
refactor(config): move `dohUserAgent` to `upstreams.userAgent`
That way it can be accessed without using `GetConfig`
This commit is contained in:
parent
4e89b44185
commit
9760735f3a
|
@ -201,7 +201,6 @@ type Config struct {
|
|||
Redis RedisConfig `yaml:"redis"`
|
||||
Log log.Config `yaml:"log"`
|
||||
Ports PortsConfig `yaml:"ports"`
|
||||
DoHUserAgent string `yaml:"dohUserAgent"`
|
||||
MinTLSServeVer string `yaml:"minTlsServeVersion" default:"1.2"`
|
||||
CertFile string `yaml:"certFile"`
|
||||
KeyFile string `yaml:"keyFile"`
|
||||
|
@ -227,6 +226,7 @@ type Config struct {
|
|||
HTTPSPorts *ListenConfig `yaml:"httpsPort"`
|
||||
TLSPorts *ListenConfig `yaml:"tlsPort"`
|
||||
StartVerifyUpstream *bool `yaml:"startVerifyUpstream"`
|
||||
DoHUserAgent *string `yaml:"dohUserAgent"`
|
||||
} `yaml:",inline"`
|
||||
}
|
||||
|
||||
|
@ -523,6 +523,7 @@ func (cfg *Config) migrate(logger *logrus.Entry) bool {
|
|||
"logPrivacy": Move(To("log.privacy", &cfg.Log)),
|
||||
"logTimestamp": Move(To("log.timestamp", &cfg.Log)),
|
||||
"startVerifyUpstream": Move(To("upstreams.startVerify", &cfg.Upstreams)),
|
||||
"dohUserAgent": Move(To("upstreams.userAgent", &cfg.Upstreams)),
|
||||
})
|
||||
|
||||
usesDepredOpts = cfg.Blocking.migrate(logger) || usesDepredOpts
|
||||
|
|
|
@ -771,6 +771,7 @@ bootstrapDns:
|
|||
func defaultTestFileConfig() {
|
||||
Expect(config.Ports.DNS).Should(Equal(ListenConfig{"55553", ":55554", "[::1]:55555"}))
|
||||
Expect(config.Upstreams.StartVerify).Should(BeFalse())
|
||||
Expect(config.Upstreams.UserAgent).Should(Equal("testBlocky"))
|
||||
Expect(config.Upstreams.Groups["default"]).Should(HaveLen(3))
|
||||
Expect(config.Upstreams.Groups["default"][0].Host).Should(Equal("8.8.8.8"))
|
||||
Expect(config.Upstreams.Groups["default"][1].Host).Should(Equal("8.8.4.4"))
|
||||
|
@ -797,7 +798,6 @@ func defaultTestFileConfig() {
|
|||
Expect(config.Caching.MaxCachingTime).Should(BeZero())
|
||||
Expect(config.Caching.MinCachingTime).Should(BeZero())
|
||||
|
||||
Expect(config.DoHUserAgent).Should(Equal("testBlocky"))
|
||||
Expect(config.MinTLSServeVer).Should(Equal("1.3"))
|
||||
|
||||
Expect(GetConfig()).Should(Not(BeNil()))
|
||||
|
@ -807,6 +807,7 @@ func writeConfigYml(tmpDir *helpertest.TmpFolder) *helpertest.TmpFile {
|
|||
return tmpDir.CreateStringFile("config.yml",
|
||||
"upstreams:",
|
||||
" startVerify: false",
|
||||
" userAgent: testBlocky",
|
||||
" groups:",
|
||||
" default:",
|
||||
" - tcp+udp:8.8.8.8",
|
||||
|
@ -859,7 +860,6 @@ func writeConfigYml(tmpDir *helpertest.TmpFolder) *helpertest.TmpFile {
|
|||
" target: /opt/log",
|
||||
"port: 55553,:55554,[::1]:55555",
|
||||
"logLevel: debug",
|
||||
"dohUserAgent: testBlocky",
|
||||
"minTlsServeVersion: 1.3",
|
||||
)
|
||||
}
|
||||
|
@ -868,6 +868,7 @@ func writeConfigDir(tmpDir *helpertest.TmpFolder) error {
|
|||
f1 := tmpDir.CreateStringFile("config1.yaml",
|
||||
"upstreams:",
|
||||
" startVerify: false",
|
||||
" userAgent: testBlocky",
|
||||
" groups:",
|
||||
" default:",
|
||||
" - tcp+udp:8.8.8.8",
|
||||
|
@ -884,7 +885,8 @@ func writeConfigDir(tmpDir *helpertest.TmpFolder) error {
|
|||
"filtering:",
|
||||
" queryTypes:",
|
||||
" - AAAA",
|
||||
" - A")
|
||||
" - A",
|
||||
)
|
||||
if f1.Error != nil {
|
||||
return f1.Error
|
||||
}
|
||||
|
@ -925,7 +927,6 @@ func writeConfigDir(tmpDir *helpertest.TmpFolder) error {
|
|||
" target: /opt/log",
|
||||
"port: 55553,:55554,[::1]:55555",
|
||||
"logLevel: debug",
|
||||
"dohUserAgent: testBlocky",
|
||||
"minTlsServeVersion: 1.3",
|
||||
)
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ type Upstreams struct {
|
|||
Groups UpstreamGroups `yaml:"groups"`
|
||||
Strategy UpstreamStrategy `yaml:"strategy" default:"parallel_best"`
|
||||
StartVerify bool `yaml:"startVerify" default:"false"`
|
||||
UserAgent string `yaml:"userAgent"`
|
||||
}
|
||||
|
||||
type UpstreamGroups map[string][]Upstream
|
||||
|
|
|
@ -26,6 +26,8 @@ upstreams:
|
|||
timeout: 2s
|
||||
# optional: If true, blocky will fail to start unless at least one upstream server per group is reachable. Default: false
|
||||
startVerify: false
|
||||
# optional: HTTP User Agent when connecting to upstreams. Default: none
|
||||
userAgent: "custom UA"
|
||||
|
||||
# optional: Determines how blocky will create outgoing connections. This impacts both upstreams, and lists.
|
||||
# accepted: dual, v4, v6
|
||||
|
|
|
@ -15,7 +15,6 @@ configuration properties as [JSON](config.yml).
|
|||
| ------------------- | ------------------- | --------- | ------------- | ---------------------------------------------------------------------------------------------------------- |
|
||||
| certFile | path | no | | Path to cert and key file for SSL encryption (DoH and DoT); if empty, self-signed certificate is generated |
|
||||
| keyFile | path | no | | Path to cert and key file for SSL encryption (DoH and DoT); if empty, self-signed certificate is generated |
|
||||
| dohUserAgent | string | no | | HTTP User Agent for DoH upstreams |
|
||||
| minTlsServeVersion | string | no | 1.2 | Minimum TLS version that the DoT and DoH server use to serve those encrypted DNS requests |
|
||||
| connectIPVersion | enum (dual, v4, v6) | no | dual | IP version to use for outgoing connections (dual, v4, v6) |
|
||||
|
||||
|
@ -75,6 +74,7 @@ All logging options are optional.
|
|||
| usptreams.startVerify | bool | no | false | If true, blocky will fail to start unless at least one upstream server per group is functional. |
|
||||
| usptreams.strategy | enum (parallel_best, random, strict) | no | parallel_best | Upstream server usage strategy. |
|
||||
| usptreams.timeout | duration | no | 2s | Upstream connection timeout. |
|
||||
| usptreams.userAgent | string | no | | HTTP User Agent when connecting to upstreams. |
|
||||
|
||||
|
||||
### Upstream Groups
|
||||
|
|
|
@ -73,8 +73,9 @@ type dnsUpstreamClient struct {
|
|||
}
|
||||
|
||||
type httpUpstreamClient struct {
|
||||
client *http.Client
|
||||
host string
|
||||
client *http.Client
|
||||
host string
|
||||
userAgent string
|
||||
}
|
||||
|
||||
func createUpstreamClient(cfg upstreamConfig) upstreamClient {
|
||||
|
@ -90,6 +91,7 @@ func createUpstreamClient(cfg upstreamConfig) upstreamClient {
|
|||
switch cfg.Net {
|
||||
case config.NetProtocolHttps:
|
||||
return &httpUpstreamClient{
|
||||
userAgent: cfg.UserAgent,
|
||||
client: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tlsConfig,
|
||||
|
@ -143,7 +145,7 @@ func (r *httpUpstreamClient) callExternal(
|
|||
return nil, 0, fmt.Errorf("can't create the new request %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", config.GetConfig().DoHUserAgent)
|
||||
req.Header.Set("User-Agent", r.userAgent)
|
||||
req.Header.Set("Content-Type", dnsContentType)
|
||||
req.Host = r.host
|
||||
|
||||
|
|
Loading…
Reference in New Issue