Files
dnsproxy/proxy/requesthandler.go
Dimitry Kolyshev 62d52341bc Pull request: AGDNS-3523-add-context
Merge in GO/dnsproxy from AGDNS-3523-add-context to master

Squashed commit of the following:

commit 59b61ecf791f4d2df54cae143b262112ed7fe241
Author: Dimitry Kolyshev <[email protected]>
Date:   Thu Mar 12 09:20:57 2026 +0700

    proxy: start ctx

commit fe4cbfbc893da6728ab22cef667a70e9180fe15b
Merge: 10c620a b7d4b05
Author: Dimitry Kolyshev <[email protected]>
Date:   Wed Mar 11 07:59:19 2026 +0700

    Merge remote-tracking branch 'origin/master' into AGDNS-3523-add-context

commit 10c620ac414cfdd4d5b1e42279bf18c5b9380f75
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Mar 10 12:21:06 2026 +0700

    proxy: fix udp

commit 6dbe12058d756479faa11d5b898b86c45117d1c5
Author: Dimitry Kolyshev <[email protected]>
Date:   Fri Mar 6 12:58:47 2026 +0700

    proxy: start ctx

commit 88cf3e781176eec709441e01d81a708c3f2e7f38
Author: Dimitry Kolyshev <[email protected]>
Date:   Thu Mar 5 11:24:26 2026 +0700

    proxy: req ctx constructor

commit f8d8e2662c39b97d4297961e40e833b09e950ed3
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Mar 3 08:53:28 2026 +0700

    proxy: todo

commit 6e32f1ebb29c54af58b1df8ad927a6babadf497f
Author: Dimitry Kolyshev <[email protected]>
Date:   Mon Mar 2 09:27:03 2026 +0700

    proxy: add context

commit 9e42af8f510c3ab23fe04950265cbcb8e8eba412
Author: Dimitry Kolyshev <[email protected]>
Date:   Sun Mar 1 09:42:30 2026 +0700

    proxy: imp code

commit 29e498d6f8fba668d810987d773624443bb7a51c
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Feb 24 13:32:27 2026 +0700

    all: add proxy context
2026-03-13 01:26:43 +00:00

43 lines
1.3 KiB
Go

package proxy
import (
"context"
"github.com/AdguardTeam/golibs/errors"
)
// ErrDrop is returned by a [Handler] to signal that the proxy should not send
// any response to the client.
const ErrDrop errors.Error = "drop response"
// Handler is an interface for handling DNS requests.
type Handler interface {
// ServeDNS resolves the DNS request within *DNSContext.
ServeDNS(ctx context.Context, p *Proxy, dctx *DNSContext) (err error)
}
// DefaultHandler implements [Handler] by calling [Proxy.Resolve]. It is used
// as a default handler if no other handler is specified.
type DefaultHandler struct{}
// type check
var _ Handler = DefaultHandler{}
// ServeDNS implements the [Handler] interface for DefaultHandler.
func (DefaultHandler) ServeDNS(ctx context.Context, p *Proxy, proxyCtx *DNSContext) (err error) {
return p.Resolve(ctx, proxyCtx)
}
// The HandlerFunc type is an adapter to allow the use of ordinary functions as
// [Handler]. If f is a function with the appropriate signature, HandlerFunc(f)
// is a [Handler] that calls f.
type HandlerFunc func(ctx context.Context, p *Proxy, dctx *DNSContext) (err error)
// type check
var _ Handler = HandlerFunc(nil)
// ServeDNS implements the [Handler] interface for HandlerFunc.
func (f HandlerFunc) ServeDNS(ctx context.Context, p *Proxy, dctx *DNSContext) (err error) {
return f(ctx, p, dctx)
}