# Fiddle requests are made over IPv4, so whilst you would normally
# only apply this translation to IPv6 addresses, for the purpose
# of demonstrating the fiddle we'll apply it to all requests. In
# production the is_ipv6 test should be uncommented.
#if (req.is_ipv6) {
declare local var.hash STRING;
declare local var.octet STRING;
set var.hash = digest.hash_md5(client.ip);
# Class E address space has first octet >= 240 (hex `f0`), so
# use `f` + low nybble extracted from hash $ at regex end is
# important to use the low-order bits of hash (which starts
# with `0x`)
if (var.hash ~ "([a-f0-9]{1})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$") {
set var.octet = "f" + re.group.1;
}
set req.http.X-IPv4 = std.strtol(var.octet, 16) + "." + std.strtol(re.group.2, 16) + "." + std.strtol(re.group.3, 16) + "." + std.strtol(re.group.4, 16);
#}