You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #! /usr/bin/env bash
  2. # source: proxyecho.sh
  3. # Copyright Gerhard Rieger and contributors (see file CHANGES)
  4. # Published under the GNU General Public License V.2, see file COPYING
  5. # perform primitive simulation of a proxy server with echo function via stdio.
  6. # accepts and answers correct HTTP CONNECT requests, but then just echoes data.
  7. # it is required for test.sh
  8. # for TCP, use this script as:
  9. # socat tcp-l:8080,reuseaddr,crlf system:"proxyecho.sh"
  10. if type socat >/dev/null 2>&1; then
  11. SOCAT=socat
  12. else
  13. SOCAT=./socat
  14. fi
  15. case `uname` in
  16. HP-UX|OSF1)
  17. CAT="$SOCAT -u stdin stdout"
  18. ;;
  19. *)
  20. CAT=cat
  21. ;;
  22. esac
  23. SPACES=" "
  24. while [ -n "$1" ]; do
  25. case "$1" in
  26. -w) n="$2"; while [ "$n" -gt 0 ]; do SPACES="$SPACES "; n=$((n-1)); done
  27. shift ;;
  28. #-s) STAT="$2"; shift ;;
  29. esac
  30. shift
  31. done
  32. # read and parse HTTP request
  33. read l
  34. if echo "$l" |egrep '^CONNECT +[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+ +HTTP/1.[01]$' >/dev/null
  35. then
  36. : go on below
  37. else
  38. echo "HTTP/1.0${SPACES}500 Bad Request"
  39. echo
  40. exit
  41. fi
  42. # read more headers until empty line
  43. while [ -n "$l" ]; do
  44. read l
  45. done
  46. # send status
  47. echo "HTTP/1.0${SPACES}200 OK"
  48. # send empty line
  49. echo
  50. # perform echo function
  51. exec $CAT