BEGIN { RS="\r\n" }
NR == 1 && $1 ~ /^HTTP\/1\../ && $2 != code { print "Fail: " $0; fail=1; nextfile; }
NR == 3 && code != 200 { nextfile; }
NR == 3 { RS="\n"; FS="="; }
$1 == "SCRIPT_NAME" && $2 != "/print_env.sh" { print "Fail: " $0; fail=1; nextfile; }
$1 == "QUERY_STRING" && ($2 != "foo" || $3 != "bar&baz" || $4 != "foo+bar") { print "Fail: " $0; fail=1; nextfile; }
$1 == "APP_NAME" && $2 == "Thx Natacha" { cgi_env=1; }

END {
  if (!cgi_env) { print "Fail: cgi_env"; fail=1; }
  if (!fail) { print "Ok"; } exit fail;
}
