althttpd.c CGI Script Requires a Throw Away First Line of Output?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

althttpd.c CGI Script Requires a Throw Away First Line of Output?

Carl Chave
I'm experimenting with the althttpd.c web server.  As a simple first test I
created a static html file and a lua script file.  The static file displays
as expected in firefox.  The lua file, which simply reads in the same
static html file and writes it back to stdout ends up being truncated and
displayed incorrectly in firefox.

If I begin the output of the script with a newline and then continue
writing out the rest of the static file contents it's fine.

The section of source code and comment that starts at line number 1706 and
continues through line 1733 seems to be the section that's causing it.  I
took the entire block out, recompiled and tested the lua script again
(without starting output with a newline) and it worked as expected.  So the
script just read in the static file and spit it back out unaltered and it
displays the same as the static file in my browser.  The returned headers
are different but the returned html is the same.

What is the correct approach?  Should I return some minimum set of headers
from the CGI script? Content type seems to be conspicuously absent when
comparing the headers between the static file and CGI script.  Or should I
just start all script output with a newline?

Thanks,
Carl
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: althttpd.c CGI Script Requires a Throw Away First Line of Output?

Richard Hipp-3
On 2/5/19, Carl Chave <[hidden email]> wrote:
> I'm experimenting with the althttpd.c web server.  As a simple first test I
> created a static html file and a lua script file.  The static file displays
> as expected in firefox.  The lua file, which simply reads in the same
> static html file and writes it back to stdout ends up being truncated and
> displayed incorrectly in firefox.
>
> If I begin the output of the script with a newline and then continue
> writing out the rest of the static file contents it's fine.

The reply from a CGI script should start with a line of the form:

    Content-Type: text/html

(or some other MIME type) and be followed by a blank line and only
then the content.  There are other options, for example to provoke a
server redirect or to set a status code other than 200.  See
https://en.wikipedia.org/wiki/Common_Gateway_Interface for additional
information,

>
> The section of source code and comment that starts at line number 1706 and
> continues through line 1733 seems to be the section that's causing it.  I
> took the entire block out, recompiled and tested the lua script again
> (without starting output with a newline) and it worked as expected.  So the
> script just read in the static file and spit it back out unaltered and it
> displays the same as the static file in my browser.  The returned headers
> are different but the returned html is the same.
>
> What is the correct approach?  Should I return some minimum set of headers
> from the CGI script? Content type seems to be conspicuously absent when
> comparing the headers between the static file and CGI script.  Or should I
> just start all script output with a newline?
>
> Thanks,
> Carl
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users