Created
February 3, 2023 06:12
-
-
Save pd12bbf7608ae1/e15b37bf946f7aac5e0478b76f4e2084 to your computer and use it in GitHub Desktop.
curlProxy.sh
This file contains 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 | |
function curlProxy() { | |
if [[ -z $apiEndpoint || -z $apiAuthorization ]]; then | |
return 1 | |
fi | |
curlPara=("$@") | |
originalUrl=${curlPara[-1]} | |
unset curlPara[-1] | |
hostName=$(echo "${originalUrl}" | sed -e 's|^[^/]*//||' -e 's|/.*$||') | |
path=$(echo "${originalUrl}" | sed -e 's|^[^/]*//||' -e "s/${hostName}//g") | |
if [[ -z ${path} ]]; then | |
path='/' | |
fi | |
curl "${curlPara[@]}" -H "apihost: ${hostName}" -H "apiAuthorization: ${apiAuthorization}" "https://${apiEndpoint}${path}" | |
return $? | |
} | |
apiEndpoint='' | |
apiAuthorization='' | |
# echo ${#} | |
if [[ ${#} -eq 0 ]]; then | |
echo "本脚本使用apiProxy代理https请求" 1>&2 | |
echo "${0} 后追加curl选项 URL放最后" 1>&2 | |
echo "样例: ${0} -X POST -d data=1234 https://httpbin.org/anything" 1>&2 | |
exit 0 | |
fi | |
export apiEndpoint apiAuthorization | |
curlProxy "$@" | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment