From d4305ad115c9e1ac4f62bfaa05929f2de8a5999d Mon Sep 17 00:00:00 2001 From: Jefferson Julio Date: Sun, 15 May 2022 20:37:44 -0300 Subject: Change timestamp format. Write request url to history file. --- rest-run | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/rest-run b/rest-run index 223ae80..97f6d1e 100755 --- a/rest-run +++ b/rest-run @@ -226,19 +226,20 @@ CACHE_DIR_CONTEXT_REQUEST="${CACHE_DIR_CONTEXT}/request" mkdir -p "$CACHE_DIR_CONTEXT_RESPONSE" > /dev/null mkdir -p "$CACHE_DIR_CONTEXT_REQUEST" > /dev/null -rest_timestamp="$(date +"%s")" -rest_request_file="$CACHE_DIR_CONTEXT_REQUEST/request-$rest_timestamp.json" +rest_method="${rest_method^^}" +rest_timestamp="$(date +"%y-%m-%d_%H:%M")" +rest_request_file="$CACHE_DIR_CONTEXT_REQUEST/$rest_method-request-$rest_timestamp.log" last_request_file="$(find "$CACHE_DIR_CONTEXT_REQUEST" -type f | sort -n | tail -1)" if [ ${#rest_response_file} -lt 1 ]; then - rest_response_file="$CACHE_DIR_CONTEXT_RESPONSE/response-$rest_timestamp.log" + rest_response_file="$CACHE_DIR_CONTEXT_RESPONSE/$rest_method-response-$rest_timestamp.log" fi if ! [[ -z "$last_request_file" || "${#last_request_file}" = "0" ]]; then last_request_file_checksum="$(cat "$last_request_file" | sha1sum | awk '{print $1}')" fi -if [[ "$rest_method" = "GET" || "$rest_method" = "get" ]]; then +if [[ "$rest_method" = "GET" ]]; then ignore_body=true fi @@ -256,6 +257,10 @@ fi # [ rest-run! +write-history () { + echo "$rest_method $rest_url" >> "$CACHE_DIR/request-history" +} + output-response () { case "$rest_output_extract" in @@ -345,6 +350,7 @@ if [ $ignore_body = false ]; then # Send request body | eval -- http -p "$httpie_print_options" --pretty=all \ "$rest_method" \"$rest_url\" $(for h in "${rest_headers[@]}"; do echo \"$h\"; done) -o "$rest_response_file" + write-history output-response current_request_checksum="$(cat "$rest_request_file" | sha1sum | awk '{print $1}')" @@ -358,6 +364,7 @@ else # Send request without body eval -- http --pretty=all -p "$httpie_print_options" \ "$rest_method" \"$rest_url\" $(for h in "${rest_headers[@]}"; do echo \"$h\"; done) -o "$rest_response_file" + write-history output-response fi -- cgit v1.2.3