The CGI routine responds with valid JavaScript beginning with the header:
print "Content-type: text/javascript\n\n";
You can get the VIA with $ENV{'HTTP_VIA'}, though you may want to set it up with an IF to see if your host supports it at first, or if it is present in the current transaction.
Same thing with client_ip... $ENV{'HTTP_CLIENT_IP'}.