Last active
November 6, 2019 13:28
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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