Skip to content

Instantly share code, notes, and snippets.

@morales2k
Last active November 6, 2019 13:28
Show Gist options
  • Save morales2k/377c02759db3508e184f4e21f6df243f to your computer and use it in GitHub Desktop.
Save morales2k/377c02759db3508e184f4e21f6df243f to your computer and use it in GitHub Desktop.
Little bash script you can pass args to and test cors headers with.
#same functionality in a bash profile function
function cors-test() {
ORIGIN=$1
URI=$2
METHOD=$3
if [ -z "$3" ] && [ -z "$METHOD" ]; then
echo -e "\033[0;33mSince you did not provide a method, the default GET will be used.\nYou can provide a third param to specify the method\n(to use with the curl -X option).\033[1;33m\033[0m\n"
METHOD="-X ${METHOD}"
fi
if [ -n "$ORIGIN" ] && [ -n "$URI" ]; then
curl ${METHOD} -H "Origin: ${ORIGIN}" --verbose "${URI}"
else
echo -e "\033[1;31mWhoops!\n\nYou need to provide at least two parameters.\n\nFirst argument: The origin domain to mock a curl call from.\n\nSecond argument, the url to hit with this cURL call to test CORS rules.\033[1;31m\033[0m\n"
fi
}
#!/bin/bash
ORIGIN=$1
URI=$2
METHOD=$3
if [ -z "$3" ] && [ -z "$METHOD" ]; then
echo -e "\033[0;33mSince you did not provide a method, the default GET will be used.\nYou can provide a third param to specify the method\n(to use with the curl -X option).\033[1;33m\033[0m\n"
METHOD="-X ${METHOD}"
fi
if [ -n "$ORIGIN" ] && [ -n "$URI" ]; then
curl ${METHOD} -H "Origin: ${ORIGIN}" --verbose "${URI}"
else
echo -e "\033[1;31mWhoops!\n\nYou need to provide at least two parameters.\n\nFirst argument: The origin domain to mock a curl call from.\n\nSecond argument, the url to hit with this cURL call to test CORS rules.\033[1;31m\033[0m\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment