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.
|
|
#! /usr/bin/env bash
# source: proxyecho.sh# Copyright Gerhard Rieger and contributors (see file CHANGES)# Published under the GNU General Public License V.2, see file COPYING
# perform primitive simulation of a proxy server with echo function via stdio.# accepts and answers correct HTTP CONNECT requests, but then just echoes data.# it is required for test.sh# for TCP, use this script as:# socat tcp-l:8080,reuseaddr,crlf system:"proxyecho.sh"
if type socat >/dev/null 2>&1; then SOCAT=socatelse SOCAT=./socatfi
case `uname` inHP-UX|OSF1) CAT="$SOCAT -u stdin stdout" ;;*) CAT=cat ;;esac
SPACES=" "while [ -n "$1" ]; do case "$1" in -w) n="$2"; while [ "$n" -gt 0 ]; do SPACES="$SPACES "; n=$((n-1)); done shift ;; #-s) STAT="$2"; shift ;; esac shiftdone
# read and parse HTTP requestread lif echo "$l" |egrep '^CONNECT +[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+ +HTTP/1.[01]$' >/dev/nullthen : go on belowelse echo "HTTP/1.0${SPACES}500 Bad Request" echo exitfi
# read more headers until empty linewhile [ -n "$l" ]; do read ldone
# send statusecho "HTTP/1.0${SPACES}200 OK"# send empty lineecho
# perform echo functionexec $CAT
|