diff --git a/demo/httpsig.py b/demo/httpsig.py index 105ae99..5e3b22c 100644 --- a/demo/httpsig.py +++ b/demo/httpsig.py @@ -118,31 +118,32 @@ class HTTPXSigAuth(httpx.Auth): self.key = key def auth_flow( - self, r: httpx.Request + self, + request: httpx.Request ): bodydigest = None - if r.content: + if request.content: bh = hashlib.new("sha256") - bh.update(r.content) + bh.update(request.content) bodydigest = "SHA-256=" + base64.b64encode(bh.digest()).decode("utf-8") date = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT") - r.headers["Date"] = date + request.headers["Date"] = date sigheaders = {} if bodydigest: - r.headers["digest"] = bodydigest + request.headers["digest"] = bodydigest sigheaders = "(request-target) user-agent host date digest content-type" else: sigheaders = "(request-target) user-agent host date accept" - logger.warning(r.headers) + logger.warning(request.headers) sigdate = SignedData( - method = r.method, - path = r.url.path, + method = request.method, + path = request.url.path, signed_list = sigheaders.split(), body_digest = bodydigest, - headers = r.headers, + headers = request.headers, ) to_be_signed = HttpSignature.build_signature_string( @@ -162,5 +163,5 @@ class HTTPXSigAuth(httpx.Auth): sig_value = f'keyId="{key_id}",algorithm="rsa-sha256",\ headers="{sigheaders}",signature="{sig.decode()}"' logger.debug(f"signed request {sig_value=}") - r.headers["signature"] = sig_value - yield r + request.headers["signature"] = sig_value + yield request