Anthony O. Asked: 2016-04-16 05:09:31 +0800 CST2016-04-16 05:09:31 +0800 CST 2016-04-16 05:09:31 +0800 CST Proxy to add CORS headers with netcat 772 I'm looking for a little script using nc which will be used to add CORS headers (at least Access-Control-Allow-Origin: *) in order for my local ionic dev application to access a remote webservice. proxy netcat http-headers 1 Answers Voted Anthony O. 2016-04-16T05:11:29+08:002016-04-16T05:11:29+08:00 Here is a little script inspired by this blog which I called 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
Here is a little script inspired by this blog which I called
cors-http-proxy.sh
: