[BusyBox] httpd and cgi
Charles Steinkuehler
charles at steinkuehler.net
Mon Apr 28 13:10:05 UTC 2003
Steven Scholz wrote:
> Hi there,
>
> I want an cgi script to generate a vaild html page that than is send
> to the browser.
>
> But I noticed that busybox' httpd itself is prepending an "HTTP/1.0
> 200 OK\n" if this is not contained in the buffer return from the cgi
> script.
>
> line 1150:
> if (firstLine) {
> /* check to see if the user script added headers */
> if (strncmp(buf, "HTTP/1.0 200 OK\n", 4) != 0) {
> bb_full_write(s, "HTTP/1.0 200 OK\n", 16);
> }
> if (strstr(buf, "ontent-") == 0) {
> bb_full_write(s, "Content-type: text/plain\n\n", 26);
> }
> firstLine=0;
> }
>
> And that "HTTP/1.0 200 OK\n" apparently causes my browser to display
> the html stuff as text instead of interpreting them.
>
> So instead of viewing a nice web page created by the cgi script I only
> see the source code of it.
>
> Is that normal, standard behaviour in handling CGI?
> How can I work around this httpd "feature"?
Learn how to write CGI scripts:
http://hoohoo.ncsa.uiuc.edu/cgi/overview.html
Basically, a CGI program should output a proper HTTP response, which is
headers followed by a blank line, then your content (see the http rfcs
for valid headers).
If you don't output any headers, most web-servers will add a minimal
header to provide a proper response code and default mime type.
If you simply output "Content-type: text/html\n\n" at the start of your
CGI, it will show up as an HTML page in the browser.
--
Charles Steinkuehler
charles at steinkuehler.net
More information about the busybox
mailing list