3 # Copyright Gerhard Rieger 2003-2009
4 # Published under the GNU General Public License V.2, see file COPYING
6 # perform primitive simulation of a proxy server with echo function via stdio.
7 # accepts and answers correct HTTP CONNECT requests, but then just echoes data.
8 # it is required for test.sh
9 # for TCP, use this script as:
10 # socat tcp-l:8080,reuseaddr,crlf system:"proxyecho.sh"
12 if type socat
>/dev
/null
2>&1; then
20 CAT
="$SOCAT -u stdin stdout"
30 -w) n
="$2"; while [ "$n" -gt 0 ]; do SPACES
="$SPACES "; n
=$
((n-1
)); done
32 #-s) STAT="$2"; shift ;;
37 # read and parse HTTP request
39 if echo "$l" |
egrep '^CONNECT +[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+ +HTTP/1.[01]$' >/dev
/null
43 echo "HTTP/1.0${SPACES}500 Bad Request"
48 # read more headers until empty line
54 echo "HTTP/1.0${SPACES}200 OK"
58 # perform echo function