Changeset

5689:e5ad3f1f48bd

mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
author Kim Alvefur <zash@zash.se>
date Sun, 01 Oct 2023 16:39:48 +0200
parents 5688:bbde136a4c29
children 5690:9bcd257dea4e
files mod_rest/example/rest.sh
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/example/rest.sh	Thu Sep 28 16:38:29 2023 +0200
+++ b/mod_rest/example/rest.sh	Sun Oct 01 16:39:48 2023 +0200
@@ -13,6 +13,8 @@
 HOST=""
 DOMAIN=""
 
+SESSION="session-read-only"
+
 if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/restrc" ]; then
 	# Config file can contain the above settings
 	source "${XDG_CONFIG_HOME:-$HOME/.config}/restrc"
@@ -23,7 +25,7 @@
 fi
 
 if [[ $# == 0 ]]; then
-	echo "${0##*/} [-h HOST] [/path] kind=(message|presence|iq) ...."
+	echo "${0##*/} [-h HOST] [-rw] [/path] kind=(message|presence|iq) ...."
 	# Last arguments are handed to HTTPie, so refer to its docs for further details
 	exit 0
 fi
@@ -35,6 +37,12 @@
 	HOST="$(hostname)"
 fi
 
+if [[ "$1" == "-rw" ]]; then
+	# To e.g. save Accept headers to the session
+	SESSION="session"
+	shift 1
+fi
+
 if [[ "$HOST" != *.* ]]; then
 	# Assumes subdomain of your DOMAIN
 	if [ -z "${DOMAIN:-}" ]; then
@@ -55,4 +63,4 @@
 	shift 1
 fi
 
-https --check-status -p b --session rest -A oauth2 -a "$HOST" --oauth2-scope "$SCOPE" "$HOST/rest$GET_PATH" "$@"
+https --check-status -p b --"$SESSION" rest -A oauth2 -a "$HOST" --oauth2-scope "$SCOPE" "$HOST/rest$GET_PATH" "$@"