Skip to content

Commit

Permalink
config: set user-agent for doh
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Nov 16, 2024
1 parent e556365 commit 41be265
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion intra/doh/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/celzero/firestack/intra/ipn"
"github.com/celzero/firestack/intra/log"
"github.com/celzero/firestack/intra/protect"
"github.com/celzero/firestack/intra/settings"
"github.com/celzero/firestack/intra/xdns"
"github.com/cloudflare/odoh-go"
"github.com/miekg/dns"
Expand Down Expand Up @@ -662,7 +663,9 @@ func (t *transport) asDohRequest(msg *dns.Msg) (req *http.Request, err error) {
}
req.Header.Set("content-type", dohmimetype)
req.Header.Set("accept", dohmimetype)
req.Header.Set("user-agent", "")
if settings.SetUserAgentForDoH.Load() {
req.Header.Set("user-agent", "Intra")
}
return
}

Expand Down
4 changes: 4 additions & 0 deletions intra/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ var EndpointIndependentFiltering = atomic.Bool{}
// for undelegated domains.
var SystemDNSForUndelegatedDomains = atomic.Bool{}

// SetUserAgentForDoH is a global flag to set User-Agent for DoH requests
// to "Intra".
var SetUserAgentForDoH = atomic.Bool{}

// L3 returns the string'd repr of engine.
func L3(engine int) string {
switch engine {
Expand Down
1 change: 1 addition & 0 deletions intra/tun2socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func UndelegatedDomains(useSystemDNS bool) {
func Transparency(eim, eif bool) {
settings.EndpointIndependentMapping.Store(eim)
settings.EndpointIndependentFiltering.Store(eif)
settings.SetUserAgentForDoH.Store(eim || eif)
log.I("tun: eim? %t / eif? %t", eim, eif)
}

Expand Down

0 comments on commit 41be265

Please sign in to comment.