Hi,

The attached patch adds to httpd support for a Status header.
This header (as per the CGI spec) is used by CGI scripts to ask the server to 
send an
HTTP response different than 200. Why is it needed, and why the script can't 
send the
"HTTP/1.0 302 Found" (or similar) by itself is beyond me...
PHP (at least in CGI mode) sends "Status: 302" and the appropriate Location 
when running
header('Location: something'). That was my motivation for the patch.

Due to efficiency and space considerations, when httpd receives a "Status: xxx" 
header it
sends "HTTP/1.0 xxx" without the textual code representation (e.g. "HTTP/1.0 
302" instead
of "HTTP/1.0 302 Found"). This works at least with Firefox 2.0.0.6 on Linux and 
IE 6 on,
well..., Windows.
If you think it's worth it, I can add proper message ("Found" etc.) handling.

Alex


       
____________________________________________________________________________________
Choose the right car based on your needs.  Check out Yahoo! Autos new Car 
Finder tool.
http://autos.yahoo.com/carfinder/
Index: networking/httpd.c
===================================================================
--- networking/httpd.c	(revision 19417)
+++ networking/httpd.c	(working copy)
@@ -1279,6 +1279,23 @@
 				}
 				buf_count += count;
 				count = 0;
+				if (buf_count >= 13) {
+					char *pos;
+					/* The header is for example: "Status: 302\r\n" */
+					if (memcmp(rbuf, "Status: ", 8) == 0 && (pos = memchr(rbuf, '\n', buf_count)) != NULL) {
+						int len = pos-rbuf + 1;
+						/* send "HTTP/1.0 " */
+						if (full_write(s, HTTP_200, 9) != 9)
+							break;
+						/* send "302\r\n" (actually,the specified code) */
+						if (full_write(s, rbuf + 8, len - 8) != len - 8)
+							break;
+						/* skip the header */
+						rbuf = pos + 1;
+						count = buf_count - len;
+						buf_count = -1; /* buffering off */
+					}
+				}
 				if (buf_count >= 4) {
 					/* check to see if CGI added "HTTP" */
 					if (memcmp(rbuf, HTTP_200, 4) != 0) {
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to