mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-27 12:13:20 -04:00
Turn _get_cookie() into a method
Since the _get_cookie() function is only used by the CookieHandler class, make the former a method of the latter to keep related logic close in the source code.
This commit is contained in:
parent
5fa2bd7e53
commit
c3839e830c
1 changed files with 10 additions and 11 deletions
|
|
@ -28,16 +28,6 @@ from isctest.asyncserver import (
|
|||
)
|
||||
|
||||
|
||||
def _get_cookie(qctx: QueryContext) -> dns.edns.CookieOption | None:
|
||||
for o in qctx.query.options:
|
||||
if o.otype == dns.edns.OptionType.COOKIE:
|
||||
cookie = o
|
||||
cookie.server = b"\x11\x22\x33\x44\x55\x66\x77\x88"
|
||||
return cookie
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def rrset(
|
||||
qname: dns.name.Name | str,
|
||||
rtype: dns.rdatatype.RdataType,
|
||||
|
|
@ -64,10 +54,19 @@ class ExampleNSHandler(QnameQtypeHandler, StaticResponseHandler):
|
|||
class CookieHandler(DomainHandler):
|
||||
domains = ["example."]
|
||||
|
||||
def _get_cookie(self, qctx: QueryContext) -> dns.edns.CookieOption | None:
|
||||
for o in qctx.query.options:
|
||||
if o.otype == dns.edns.OptionType.COOKIE:
|
||||
cookie = o
|
||||
cookie.server = b"\x11\x22\x33\x44\x55\x66\x77\x88"
|
||||
return cookie
|
||||
|
||||
return None
|
||||
|
||||
async def get_responses(
|
||||
self, qctx: QueryContext
|
||||
) -> AsyncGenerator[DnsResponseSend, None]:
|
||||
if cookie := _get_cookie(qctx):
|
||||
if cookie := self._get_cookie(qctx):
|
||||
# If there is a client cookie, mock BADCOOKIE to trigger
|
||||
# the resend loop logic.
|
||||
qctx.response.use_edns(options=[cookie])
|
||||
|
|
|
|||
Loading…
Reference in a new issue