On Mon, Feb 3, 2014 at 9:11 PM, Sean Woods <s...@seanwoods.com> wrote:
> I have a very basic althttpd setup: > > fieldston:test swoods$ tree > . > └── default.website > ├── cgi > ├── cgi.c > └── index.html > > 1 directory, 3 files > > `cgi` is a build of `cgi.c`, which is: > > fieldston:test swoods$ cat default.website/cgi.c > #include <stdlib.h> > #include <stdio.h> > > int main(int argc, char *argv[]) { > printf("Content-type: text/html\r\n"); > printf("Connection: close\r\n\r\n"); > printf("<h1>Hello, world!</h1>"); > return 1; > } > > I run althttpd using the `-port` command to create a standalone server. > > My problem is: while requesting a static resource with this method works > just fine, requesting a CGI resource - even with `Connection: close` as > a header - doesn't return right away. It seems to be waiting for an > additional connection (keep-alive ish). > > What's the "proper" way to send CGI output to althttpd? I tried a > `Content-length` parameter and that does work, but it means I need to > buffer my output for each response - and I thought the server was > supposed to do that for me? > > Looking at the code, it appears that althttpd.c is *not* adding the Content-Length: header if the CGI program omits it. A missing Content-Length on the reply can confuse many web-browsers. It appears that althttpd.c CGI looks at just the first line of the reply from the CGI. It takes action only if that first line is "location:" or "status:". Otherwise, the first line and everything that follows is blindly copied through and sent back to the browser, with no additional parsing, and without adding any Content-Length or other header fields. Fossil is the most common CGI program run from althttpd. And Fossil does supply a Content-Length, as well as other relevant header fields. So this issue has never come up before. -- D. Richard Hipp d...@sqlite.org _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users