答案1
以下是受以下启发的小脚本:这个博客我称之为cors-http-proxy.sh
:
#!/bin/sh -e
if [ $# != 3 ]
then
echo "usage: $0 <src-port> <dst-host> <dst-port>"
exit 0
fi
while true; do
TMP=`mktemp -d`
BACK=$TMP/pipe.back
SENT=$TMP/pipe.sent
RCVD=$TMP/pipe.rcvd
trap 'rm -rf "$TMP"' EXIT
mkfifo -m 0600 "$BACK" "$SENT" "$RCVD"
sed 's/^/ => /' <"$SENT" &
sed 's/^/<= /' <"$RCVD" &
nc -l -p "$1" <"$BACK" | sed -u "s/^Host: .*$/Host: $2:$3/" | tee "$SENT" | nc "$2" "$3" | sed -u "/^Date: /a Access-Control-Allow-Origin: *" | tee "$RCVD" >"$BACK"
done