mirror of
https://codeberg.org/vlw/curl.git
synced 2025-09-13 16:23:41 +02:00
feat: add header.json for setting request headers
This commit is contained in:
parent
d9fa939da5
commit
806e465ea2
2 changed files with 13 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
key.txt
|
||||
params.txt
|
||||
headers.json
|
||||
payload.json
|
||||
disable_peer_validation
|
22
curl.sh
22
curl.sh
|
@ -8,8 +8,8 @@ fi
|
|||
|
||||
URL="$1"
|
||||
METHOD="$2"
|
||||
KEY_FILE="key.txt"
|
||||
PARAMS_FILE="params.txt"
|
||||
HEADERS_FILE="headers.json"
|
||||
PAYLOAD_FILE="payload.json"
|
||||
DISABLE_SSL_FILE="disable_peer_validation"
|
||||
|
||||
|
@ -19,22 +19,24 @@ if [ -f $PARAMS_FILE ]; then
|
|||
URL="${URL}?${PARAMS}"
|
||||
fi
|
||||
|
||||
# Check if the key file exists and read the Bearer token
|
||||
if [ -f $KEY_FILE ]; then
|
||||
BEARER_TOKEN=$(<"$KEY_FILE")
|
||||
else
|
||||
echo "Error: Bearer token file '$KEY_FILE' not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prepare the curl command
|
||||
CURL_CMD="curl -s -H \"Authorization: Bearer ${BEARER_TOKEN}\""
|
||||
CURL_CMD="curl -s"
|
||||
|
||||
# Check if SSL peer validation should be disabled
|
||||
if [ -f $DISABLE_SSL_FILE ]; then
|
||||
CURL_CMD="$CURL_CMD -k"
|
||||
fi
|
||||
|
||||
# Add headers from headers.json
|
||||
if [ -f $HEADERS_FILE ]; then
|
||||
# Read headers from the JSON file
|
||||
while IFS= read -r line; do
|
||||
HEADER_NAME=$(echo "$line" | jq -r '.[keys[0]]')
|
||||
HEADER_VALUE=$(echo "$line" | jq -r '.[keys[1]]')
|
||||
CURL_CMD="$CURL_CMD -H \"$HEADER_NAME: $HEADER_VALUE\""
|
||||
done < <(jq -c 'to_entries | .[]' "$HEADERS_FILE")
|
||||
fi
|
||||
|
||||
# Add the request method and URL to the curl command
|
||||
CURL_CMD="$CURL_CMD -X $METHOD \"$URL\""
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue