From 9683c12bbdfadcacd4d0f936b965a5a38b25be7e Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Mon, 17 Sep 2012 16:35:52 -0500 Subject: [PATCH] fix HTTP redirect --- cgi.c | 2 +- test.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cgi.c b/cgi.c index 8cd6249..f795662 100644 --- a/cgi.c +++ b/cgi.c @@ -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); } diff --git a/test.sh b/test.sh index e5a2719..f0f5a0c 100755 --- a/test.sh +++ b/test.sh @@ -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"