How can I make an xinetd service such that a web browser can reliably show its output?
The service always sees the HTTP GET request on its stdin, and sends its reply to stdout. xinetd handles the tcp connection.
Firefox sometimes correctly shows the output. But sometimes it claims that the server reset the connection while it was still loading the page. Sometimes it shows all output, but keeps waiting for more (and when I then press ESC, it makes a new connection to the server with an empty HTTP request).
The definition for the xinetd service is:
service test
{
disable = no
id = test
type = UNLISTED
port = 8043
wait = no
socket_type = stream
flags = IPv4
user = root
server = /usr/local/bin/test.sh
}
The script for this simple test ignores the input, just echoes a minimal html. It causes the same problem as the real thing, eventhough there I added a command to close stdout at the end.
echo 'HTTP/1.1 200 OK'
echo 'Content-Type: text/html; charset=UTF-8'
echo ''
echo '<html>'
echo '<body style="background:#dfd">'
echo '<b>hello, world!</b><br>'
echo `date`
echo '</body>'
echo '</html>'
How is this different from what a web server would do?
I Found two possible answers in xinetd 'connection reset by peer':
Turns out I must do both, plus one more:
HTTP/1.0
instead ofHTTP/1.1
cat
Does anybody see an easier way? Imho the HTTP/1.1 standard does allow to omit Content-Length and instead close the connection. And where is the difference between one
cat
and a series ofecho
commands?cat or echo are both acceptable. In both cases, the data goes to standard out.
An HTTP Response can be sent with the following bash function:
I wrote a mini bash-http service for xinetd that might be helpful.
http://github.com/rglaue/xinetd_bash_http_service
It accepts HTTP/1.0 requests, including the parsing of HTTP headers like the HTTP request and parameters. And it returns an appropriate HTTP response. It is also command-line friendly.