From: Michał Kępień Date: Thu, 21 May 2026 09:52:56 +0000 (+0200) Subject: Turn _get_cookie() into a method X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=0cbf295bcacc946fbb987ac1d70dcdc9ce8ccbb0;p=thirdparty%2Fbind9.git 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. (cherry picked from commit c3839e830cfa5a8cd3ef4bdd3e5db7c0c0ee01dc) --- diff --git a/bin/tests/system/resend_loop/ans3/ans.py b/bin/tests/system/resend_loop/ans3/ans.py index 8cd94fbfee1..ad23c82939a 100644 --- a/bin/tests/system/resend_loop/ans3/ans.py +++ b/bin/tests/system/resend_loop/ans3/ans.py @@ -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, @@ -57,10 +47,19 @@ class RootNSHandler(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])