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
This commit is contained in:
Nozomi Kawamoto 2023-01-31 22:13:00 +09:00
parent 2b51904a35
commit f15417d662
1 changed files with 1 additions and 1 deletions

View File

@ -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,