I'm having some trouble with lighttpd and CGI scripts in terms of how stdin is handled. Lighttpd seems to close stdin immediately after the client has issued the GET request. Previously, I was able to use thttpd to permit a http client to connect to port 80, and then be transparently redirected to a separate internal port. This let me do fun stuff with Adobe Flash and XML sockets. I should explain this more. The client can be anything, an Adobe app, some mobile app, it sends GET /redirect.cgi to the server, the server's web server then hands that off to the CGI, the CGI process then has a socket connection to that client over which it can send/receive anything it wants. Here's an example of a simple CGI that does this using netcat as the server:
(server is just nc -l 9999 )
test@test:/var/www/cgi-bin$ cat > redirect.cgi <<EOF ; chmod 0755 redirect.cgi
#!/bin/sh
echo -e "Content-type: text/html\r\n\r\n";`
nc 127.0.0.1 9999
EOF
and now we connect to the web server and issue the GET to the cgi, then talk on both the client and server :
-- client test
nc 127.0.0.1 80
GET /cgi-bin/redirect.cgi HTTP/1.0
HOST: test.example.com
HTTP/1.0 200 OK
Content-type: text/html
server: this is the server speaking
client: this is is a test
As you can see above, the client's GET request causes thttpd to execute redirect.cgi and stdin remains open, thus allowing us to keep sending data to the server until we close the client socket. In contrast, with lighttpd, I see:
GET /cgi-bin/redirect.cgi HTTP/1.0
HOST: test.example.com
HTTP/1.0 200 OK
Content-type: text/html
Connection: close
Date: Tue, 29 May 2012 11:35:37 GMT
Server: lighttpd/1.4.26
With lighttpd, the cgi's stdin gets closed immediately. Is there a way I can configure lighttpd to behave differently? Alternatively, is there a different type of request (maybe POST or CONNECT?) that can be used to achieve the desired behavior? I tried POST but it seems there's a fixed content-length which won't work for me, CONNECT seems to behave the same as GET /. I need lighttpd to keep the CGI's stdin open until the client has closed its socket. Any suggestions would be welcome.
I also tried to use mod_proxy. So I did:
$HTTP["host"] =~ "" {
proxy.server = (
"/testport" => (
"test" => (
"host" => "127.0.0.1",
"port" => 9999,
)
)
)
}
and what I see is:
$ nc -C -l 9999
GET /testport HTTP/1.0
Host: www.example.com
X-Forwarded-For: 127.0.0.1
X-Host: www.example.com
X-Forwarded-Proto: http
server: saying hello
blah
but the "server: saying hello" stuff never goes back to the client so that didn't work for me either.