mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-15 18:08:30 -07:00
all: safesearch rewrites
This commit is contained in:
parent
88add21831
commit
fb6e66971b
@ -40,9 +40,6 @@ func (s *Server) filterDNSRequest(dctx *dnsContext) (res *filtering.Result, err
|
|||||||
// TODO(a.garipov): Make CheckHost return a pointer.
|
// TODO(a.garipov): Make CheckHost return a pointer.
|
||||||
res = &resVal
|
res = &resVal
|
||||||
switch {
|
switch {
|
||||||
case res.IsFiltered && res.CanonName == "":
|
|
||||||
log.Debug("dnsforward: host %q is filtered, reason: %q", host, res.Reason)
|
|
||||||
pctx.Res = s.genDNSFilterMessage(pctx, res)
|
|
||||||
case res.Reason.In(
|
case res.Reason.In(
|
||||||
filtering.Rewritten,
|
filtering.Rewritten,
|
||||||
filtering.RewrittenRule,
|
filtering.RewrittenRule,
|
||||||
@ -53,6 +50,9 @@ func (s *Server) filterDNSRequest(dctx *dnsContext) (res *filtering.Result, err
|
|||||||
// original question is readded in processFilteringAfterResponse.
|
// original question is readded in processFilteringAfterResponse.
|
||||||
dctx.origQuestion = q
|
dctx.origQuestion = q
|
||||||
req.Question[0].Name = dns.Fqdn(res.CanonName)
|
req.Question[0].Name = dns.Fqdn(res.CanonName)
|
||||||
|
case res.IsFiltered:
|
||||||
|
log.Debug("dnsforward: host %q is filtered, reason: %q", host, res.Reason)
|
||||||
|
pctx.Res = s.genDNSFilterMessage(pctx, res)
|
||||||
case res.Reason.In(filtering.Rewritten, filtering.FilteredSafeSearch):
|
case res.Reason.In(filtering.Rewritten, filtering.FilteredSafeSearch):
|
||||||
pctx.Res = s.getCNAMEWithIPs(req, res.IPList, res.CanonName)
|
pctx.Res = s.getCNAMEWithIPs(req, res.IPList, res.CanonName)
|
||||||
case res.Reason.In(filtering.RewrittenRule, filtering.RewrittenAutoHosts):
|
case res.Reason.In(filtering.RewrittenRule, filtering.RewrittenAutoHosts):
|
||||||
|
@ -609,11 +609,10 @@ func (s *Server) processFilteringAfterResponse(dctx *dnsContext) (rc resultCode)
|
|||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
pctx.Req.Question[0], pctx.Res.Question[0] = dctx.origQuestion, dctx.origQuestion
|
pctx.Req.Question[0], pctx.Res.Question[0] = dctx.origQuestion, dctx.origQuestion
|
||||||
if len(pctx.Res.Answer) > 0 {
|
|
||||||
rr := s.genAnswerCNAME(pctx.Req, res.CanonName)
|
rr := s.genAnswerCNAME(pctx.Req, res.CanonName)
|
||||||
answer := append([]dns.RR{rr}, pctx.Res.Answer...)
|
answer := append([]dns.RR{rr}, pctx.Res.Answer...)
|
||||||
pctx.Res.Answer = answer
|
pctx.Res.Answer = answer
|
||||||
}
|
|
||||||
|
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
default:
|
default:
|
||||||
|
@ -559,6 +559,8 @@ type Result struct {
|
|||||||
Reason Reason `json:",omitempty"`
|
Reason Reason `json:",omitempty"`
|
||||||
|
|
||||||
// IsFiltered is true if the request is filtered.
|
// IsFiltered is true if the request is filtered.
|
||||||
|
//
|
||||||
|
// TODO(d.kolyshev): Get rid of this flag.
|
||||||
IsFiltered bool `json:",omitempty"`
|
IsFiltered bool `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +92,9 @@ func TestDefault_CheckHost_yandex(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
require.Len(t, res.Rules, 1)
|
require.Len(t, res.Rules, 1)
|
||||||
|
|
||||||
assert.Equal(t, tc.want, res.Rules[0].IP)
|
rule := res.Rules[0]
|
||||||
assert.Equal(t, rulelist.URLFilterIDSafeSearch, res.Rules[0].FilterListID)
|
assert.Equal(t, tc.want, rule.IP)
|
||||||
|
assert.Equal(t, rulelist.URLFilterIDSafeSearch, rule.FilterListID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user