Make sample web server close connections

The sample web server, using nc, currently does not close the
connection after serving the content.  This can cause clients to
hang waiting for the connection to close after the content has been
served.  This patch includes the content length in the response
so that the connection will close.

Change-Id: I9443157f1edd8ed7e90599df73f5a48f16c955f1
This commit is contained in:
Michael Johnson 2016-01-19 19:40:39 +00:00
parent 820829d36b
commit 158bb0d91a
1 changed files with 4 additions and 1 deletions

View File

@ -1,6 +1,9 @@
#!/bin/sh
MYIP=$(/sbin/ifconfig eth0|grep 'inet addr'|awk -F: '{print $2}'| awk '{print $1}');
OUTPUT_STR="Welcome to $MYIP\r"
OUTPUT_LEN=${#OUTPUT_STR}
while true; do
echo -e "HTTP/1.0 200 OK\r\n\r\nWelcome to $MYIP" | sudo nc -l -p 80
echo -e "HTTP/1.0 200 OK\r\nContent-Length: ${OUTPUT_LEN}\r\n\r\n${OUTPUT_STR}" | sudo nc -l -p 80
done