From f15417d662f9119c04d3cab85d5c807b36d8fa8f Mon Sep 17 00:00:00 2001 From: Nozomi Kawamoto Date: Tue, 31 Jan 2023 22:13:00 +0900 Subject: [PATCH] Support IPv6 for HTTP request This http-healthcheck always fails in the case the request is against to IPv6 address. Usually, the socket in IPv6 return a tuple that contains four values but only two values in IPv4. Currently, only two variables are defined to store return values. Therefore when extract the return value of socket.getpeername() in IPv6, an ValueError exception is raised and then healthcheck fails. This change restrict the return value of the socket.getpeername() to return only first two elements regardless of IPv4/IPv6. Closes-Bug: #2004268 Change-Id: I57ae54518a86f93ec92f0e74efadf1fa4da29f0f --- healthcheck/http-healthcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthcheck/http-healthcheck.py b/healthcheck/http-healthcheck.py index ec731a1bf..223d7e592 100755 --- a/healthcheck/http-healthcheck.py +++ b/healthcheck/http-healthcheck.py @@ -30,7 +30,7 @@ output = args.write_out.replace('%{', '%(').replace('}', ')s') \ headers = {'User-Agent': args.user_agent} with requests.get(uri, headers=headers, timeout=args.max_time, allow_redirects=True, stream=True, verify=False) as req: - r_ip, r_port = req.raw._original_response.fp.raw._sock.getpeername() + r_ip, r_port = req.raw._original_response.fp.raw._sock.getpeername()[0:2] resp = {'http_code': req.status_code, 'remote_ip': r_ip, 'remote_port': r_port,