fix HTTP redirect

This commit is contained in:
Neale Pickett 2012-09-17 16:35:52 -05:00
parent f56fbd7477
commit 9683c12bbd
2 changed files with 10 additions and 1 deletions

2
cgi.c
View File

@ -111,7 +111,7 @@ cgi_parent(int cin, int cout, int passthru)
if (! header_sent) {
if (! strcasecmp(cgiheader, "Location")) {
header(302, "CGI Redirect");
fwrite(cgiheader, 1, cgiheaderlen, stdout);
printf("%s: %s\r\n\r\n", cgiheader, val);
dolog(302, 0);
exit(0);
}

View File

@ -55,6 +55,12 @@ echo 'james'
EOD
chmod +x default/mongo.cgi
cat <<'EOD' > default/redir.cgi
#! /bin/sh
echo "Location: http://example.com/froot"
EOD
chmod +x default/redir.cgi
mkdir -p default/empty
mkdir -p default/subdir
touch default/subdir/a
@ -202,6 +208,9 @@ printf 'GET /a.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | d | grep -Eq '%S
title "Large response"
printf 'GET /mongo.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | grep -q james && pass || fail
title "Redirect"
printf 'GET /redir.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | grep -Fq 'Location: http://example.com/froot' && pass || fail
H "Timeouts"