3 # Copyright Gerhard Rieger and contributors (see file CHANGES)
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 # 20230423 GR Added option -V to require particular HTTP version
14 if type socat
>/dev
/null
2>&1; then
22 CAT
="$SOCAT -u stdin stdout"
32 -w) n
="$2"; while [ "$n" -gt 0 ]; do SPACES
="$SPACES "; n
=$
((n-1
)); done
34 -V) shift; REQVER
="$1" ;;
35 #-s) STAT="$2"; shift ;;
40 # read and parse HTTP request
42 if ! echo "$l" |
egrep '^CONNECT +[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+ +HTTP/[1-3].[0-9]$' >/dev
/null
44 echo "HTTP/1.0${SPACES}500 Bad Request"
48 if ! echo "$l" |
egrep '^CONNECT +[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+ +HTTP/'"$REQVER"'$' >/dev
/null
50 echo "HTTP/1.0${SPACES}426 Upgrade Required"
55 # read more headers until empty line
61 echo "HTTP/$REQVER${SPACES}200 OK"
65 # perform echo function