Functions: adds httpie helpers for xsrf

The functions are wrappers around http and https and set the
x-xsrf-token header based on the value of the Xsrf-token cookie in the
session file.

Currently, the cookie name and header name are hard coded. I may look to
specify those in an argument at some point although for now it's
probably fine.
Jonathan Hodgson 3 years ago
parent 92b5ac3e4c
commit d967936fde
  1. 14
      shells/shared/functions

@ -325,3 +325,17 @@ function cat(){
/usr/bin/bat "$@"
fi
}
# These functions extend httpie in order to add an X-XSRF-TOKEN header based on the value of a cookie.
http-xsrf(){
sessionfile="$(echo "$*" | grep -Eo -- '--session[= ][^ ]*' | sed 's/^--session[= ]//')"
cookie="$(jq -r '.cookies."XSRF-TOKEN".value' "$sessionfile")"
http "$@" "X-XSRF-TOKEN:$cookie"
}
https-xsrf(){
sessionfile="$(echo "$*" | grep -Eo -- '--session[= ][^ ]*' | sed 's/^--session[= ]//')"
cookie="$(jq -r '.cookies."XSRF-TOKEN".value' "$sessionfile")"
https "$@" "X-XSRF-TOKEN:$cookie"
}

Loading…
Cancel
Save