I wanted to write this post as I was facing issues while installing formula use homebrew command on Mac OS behind proxy, finally I was able to do it using info given on this page.
Its really simple just use the http_proxy or https_proxy before the brew install command or any brew command you want to run behind proxy.
https_proxy=https://username:password@proxy:port brew install apache-spark
http_proxy=http://username:password@proxy:port brew install $other_formula
Also one can set the git config settings for http.proxy and https.proxy like below:
git config –global http.proxy http://username:password@proxy:port
git config –global https.proxy https://username:password@proxy:port
These above settings will make sure to pass through proxies while brew connects to git repository.
Enjoy and thanks for reading.