Compare commits

..

No commits in common. "master" and "2.1.2" have entirely different histories.

11
curl.sh
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Check if the correct number of arguments is provided # Check if the correct number of arguments is provided
if [ -z "${1:-}" ]; then if [ "$#" -ne 1 ]; then
echo "Usage: $0 <url> [request_method]" echo "Usage: $0 <url> [request_method]"
exit 1 exit 1
fi fi
@ -23,11 +23,8 @@ method="${2:-GET}"
if [ -f $REQ_PARAMS_FILE ]; then if [ -f $REQ_PARAMS_FILE ]; then
# Parse each newline as a separate parameter joined by a "&" # Parse each newline as a separate parameter joined by a "&"
params=$(tr '\n' '&' < "$REQ_PARAMS_FILE" | sed 's/&$//') params=$(tr '\n' '&' < "$REQ_PARAMS_FILE" | sed 's/&$//')
if [ -n "$params" ]; then
url="${url}?${params}" url="${url}?${params}"
fi fi
fi
# Prepare curl # Prepare curl
curl_cmd="curl -s" curl_cmd="curl -s"
@ -66,7 +63,9 @@ fi
# Save the response headers and body # Save the response headers and body
curl_cmd="$curl_cmd -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE" curl_cmd="$curl_cmd -o $RESP_BODY_RAW_FILE -D $RESP_HEADERS_FILE"
# Dispatch request # Execute curl
eval "clear"
echo -e "\e[0;92mRequest >\e[0m ${method} ${url}" echo -e "\e[0;92mRequest >\e[0m ${method} ${url}"
eval $curl_cmd eval $curl_cmd
@ -74,4 +73,4 @@ eval $curl_cmd
jq . $RESP_BODY_RAW_FILE > $RESP_BODY_JSON_FILE jq . $RESP_BODY_RAW_FILE > $RESP_BODY_JSON_FILE
# Print the response code # Print the response code
echo -e -n "\e[0;94mResponse <\e[0m "; head -n 1 $RESP_HEADERS_FILE echo -e -n "\e[0;94mResponse <\e[0m "; awk 'NR==1{print $2, $3; exit}' $RESP_HEADERS_FILE