Skip to content

Instantly share code, notes, and snippets.

@eatnumber1
Created April 21, 2011 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eatnumber1/934798 to your computer and use it in GitHub Desktop.
Save eatnumber1/934798 to your computer and use it in GitHub Desktop.
Drink Sunday -> HTTP Proxy
#!/bin/zsh
emulate -L zsh
typeset -r PROGRAM="$0"
function parent() {
typeset -r HOST="${${PROGRAM##*/}%\.cgi}.csh.rit.edu"
echo "Content-Type: text/plain"
echo
CHILD=1 exec /usr/bin/socat OPENSSL:"$HOST":4243,cafile=/etc/ssl/certs/csh-ca.pem EXEC:"$PROGRAM",fdin=3,fdout=4,sighup,sigint,sigquit
}
function child() {
local cmd line
while read -ru 3 line; do
print -r "$line"
if [[ $line =~ (OK|ERR).* ]]; then
read -r cmd || exit 0
print -ru 4 "$cmd"
fi
done
}
if (( ${+CHILD} )); then
exec child
else
exec parent
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment