nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #! /bin/bash |
2 | # source: proxyecho.sh |
||
3 | # Copyright Gerhard Rieger 2003-2009 |
||
4 | # Published under the GNU General Public License V.2, see file COPYING |
||
5 | |||
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" |
||
11 | |||
12 | if type socat >/dev/null 2>&1; then |
||
13 | SOCAT=socat |
||
14 | else |
||
15 | SOCAT=./socat |
||
16 | fi |
||
17 | |||
18 | case `uname` in |
||
19 | HP-UX|OSF1) |
||
20 | CAT="$SOCAT -u stdin stdout" |
||
21 | ;; |
||
22 | *) |
||
23 | CAT=cat |
||
24 | ;; |
||
25 | esac |
||
26 | |||
27 | SPACES=" " |
||
28 | while [ -n "$1" ]; do |
||
29 | case "$1" in |
||
30 | -w) n="$2"; while [ "$n" -gt 0 ]; do SPACES="$SPACES "; n=$((n-1)); done |
||
31 | shift ;; |
||
32 | #-s) STAT="$2"; shift ;; |
||
33 | esac |
||
34 | shift |
||
35 | done |
||
36 | |||
37 | # read and parse HTTP request |
||
38 | read l |
||
39 | if echo "$l" |egrep '^CONNECT +[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+ +HTTP/1.[01]$' >/dev/null |
||
40 | then |
||
41 | : go on below |
||
42 | else |
||
43 | echo "HTTP/1.0${SPACES}500 Bad Request" |
||
44 | echo |
||
45 | exit |
||
46 | fi |
||
47 | |||
48 | # read more headers until empty line |
||
49 | while [ -n "$l" ]; do |
||
50 | read l |
||
51 | done |
||
52 | |||
53 | # send status |
||
54 | echo "HTTP/1.0${SPACES}200 OK" |
||
55 | # send empty line |
||
56 | echo |
||
57 | |||
58 | # perform echo function |
||
59 | exec $CAT |