Skip to content

Commit

Permalink
Adds user customizable DoH upstream user agent (#525)
Browse files Browse the repository at this point in the history
* Adds user customizable DoH upstream user agent

* Changed default user agent to empty
  • Loading branch information
FileGo authored May 18, 2022
1 parent 43d3e15 commit 776c51f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ type Config struct {
HTTPPorts ListenConfig `yaml:"httpPort"`
HTTPSPorts ListenConfig `yaml:"httpsPort"`
TLSPorts ListenConfig `yaml:"tlsPort"`
DoHUserAgent string `yaml:"dohUserAgent"`
// Deprecated
DisableIPv6 bool `yaml:"disableIPv6" default:"false"`
CertFile string `yaml:"certFile"`
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var _ = Describe("Config", func() {
Expect(config.Caching.MaxCachingTime).Should(Equal(Duration(0)))
Expect(config.Caching.MinCachingTime).Should(Equal(Duration(0)))

Expect(config.DoHUserAgent).Should(Equal("testBlocky"))

Expect(GetConfig()).Should(Not(BeNil()))

})
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ configuration properties as [JSON](config.yml).
| logLevel | enum (debug, info, warn, error) | no | info | Log level |
| logFormat | enum (text, json) | no | text | Log format (text or json). |
| logTimestamp | bool | no | true | Log time stamps (true or false). |
| logPrivacy | bool | no | false | Obfuscate log output (replace all alphanumeric characters with *) for user sensitive data like request domains or responses to increase privacy. |
| logPrivacy | bool | no | false | Obfuscate log output (replace all alphanumeric characters with *) for user sensitive data like request domains or responses to increase privacy. |
| dohUserAgent | string | no | | HTTP User Agent for DoH upstreams |

!!! example

Expand Down
2 changes: 1 addition & 1 deletion resolver/upstream_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *httpUpstreamClient) callExternal(msg *dns.Msg,
return nil, 0, fmt.Errorf("can't create the new request %w", err)
}

req.Header.Set("User-Agent", "")
req.Header.Set("User-Agent", config.GetConfig().DoHUserAgent)
req.Header.Set("Content-Type", dnsContentType)
httpResponse, err := r.client.Do(req)

Expand Down
1 change: 1 addition & 0 deletions testdata/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ queryLog:

port: 55553,:55554,[::1]:55555
logLevel: debug
dohUserAgent: testBlocky

0 comments on commit 776c51f

Please sign in to comment.