Skip to content

Instantly share code, notes, and snippets.

@jwendell
Created September 4, 2018 22:49
Show Gist options
  • Save jwendell/b77f79062f866d183eaf5fa8a215599f to your computer and use it in GitHub Desktop.
Save jwendell/b77f79062f866d183eaf5fa8a215599f to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z "${GATEWAY_URL}" ]; then
echo "Set the GATEWAY_URL variable first"
exit 1
fi
# $1: If non empty, simulates user logged in
# $2: If non empty, simulates a different source ip
function exec_curl() {
local count200=0
local count429=0
local headers="-Ha=b"
local user_agent=""
if [ -n "$1" ]; then
headers="-H \"Cookie: session=xuxa\" $headers "
user_agent="${user_agent}_user_logged_in"
fi
if [ -n "$2" ]; then
headers="-H \"x-forwarded-for: 1.2.3.4\" $headers "
user_agent="${user_agent}_different_ip"
fi
if [ -z "${user_agent}" ]; then
user_agent="anonymous"
fi
#set -x
#curl -I -A ${user_agent} "${headers}" http://${GATEWAY_URL}/productpage
#set +x
#return
for i in {1..10}; do
echo -n "Trying http://${GATEWAY_URL}/productpage -A ${user_agent} ${headers}... "
res=$(curl -o /dev/null -s -w "%{http_code}\n" -A ${user_agent} "${headers}" http://${GATEWAY_URL}/productpage)
echo "$res"
if [ "$res" = "200" ]; then
((count200++))
else
((count429++))
fi
sleep 0.1
done
echo -e "Total: 200 = $count200\t429 = $count429"
echo
}
exec_curl
exec_curl 1 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment