shithub: riscv

Download patch

ref: c2aa8c997aa9f7a6f0bc6cb1ad99cccede44fc72
parent: 658c1b9f68065a4e9ac7f1e28b3eedbba36c3099
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Dec 17 15:26:38 EST 2020

hpost: support custom headers (thanks julienxx)

hget supports adding custom headers with -r;
it makes sense for hpost to do the same, both
because custom headers are more likely necessary
with POSTs, and for consistency.

--- a/rc/bin/hpost
+++ b/rc/bin/hpost
@@ -1,12 +1,15 @@
 #!/bin/rc
 rfork e
 url=()
+headers=()
+action=()
+method=()
 at=()	# text fields
 af=()	# file fields
 l=()
 
 fn usage {
-	echo 'usage: hpost [ -l ] [ -[gpm] action ] [ -u ] url [ field:value | field@file ... ]' >[1=2]
+	echo 'usage: hpost [ -l ] [ -[gpm] action ] [ -r ] header [ -u ] url [ field:value | field@file ... ]' >[1=2]
 	exit usage
 }
 
@@ -14,6 +17,7 @@
 	switch($1){
 	case -l;	l=($l $1)
 	case -u;	shift; url=$1
+	case -r;	shift; headers=($headers -r $1)
 	case -g;	shift; action=$1; method=mget
 	case -p;	shift; action=$1; method=mpost
 	case -m;	shift; action=$1; method=multi
@@ -94,8 +98,9 @@
 	menc $"f | $hget -r 'Content-Type: multipart/form-data; boundary='$"f -b $url -P $action
 }
 
+
 if(! ~ $action ''){
-	hget=(hget $l)
+	hget=(hget $headers $l)
 	$method
 	exit
 }
--- a/sys/man/1/hget
+++ b/sys/man/1/hget
@@ -38,6 +38,9 @@
 .B -m
 .I action
 ] [
+.B -r
+.I header
+] [
 .B -u
 ]
 .I url
@@ -119,6 +122,9 @@
 .B -r
 sends an arbitrary HTTP
 .IR header .
+The
+.B -r
+flag can be repeated to send multiple headers.
 .PP
 Option
 .B -m