Fix tests to work when localhost is IPv6

On some systems localhost is mapped as both 127.0.0.1 and ::1, which
was causing some of the tests (e.g. for X-Forwarded-For) to fail.