9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Julien Blanchard <julien@typed-hole.org>
To: ori@eigenstate.org, 9front@9front.org
Subject: Re: [9front] [PATCH] Update hpost to use -r header like hget
Date: Wed, 16 Dec 2020 19:16:22 +0100	[thread overview]
Message-ID: <b13de105-af36-76fd-af65-e697264ae3f7@typed-hole.org> (raw)
In-Reply-To: <EEE2530F13BFE807311AEE3CD02AA3CD@eigenstate.org>

On 15/12/2020 19:42, ori@eigenstate.org wrote:
> 
> unrelated to your change, but while we're here:
> if you could also set action=()/method=(), that
> would prevent them from leaking in through the
> environment.
> 

Done

> 
> This only supports one header. hget allows repeated
> -r flags to add multiple headers:
> 
> 	hget -r foo -r bar
> 
> The change for multiple headers should be as simple
> as one change here:
> 
> 	headers=($headers $1)
> 
>> +	if not
>> +		hget=(hget -r $header $l)
> 
> 
> And one here here:
> 
> 	-r^$headers
> 
> which will distribute -r across all of the
> entries in the headers list.
> 
> As a reminder: in rc,
> 
> 	foo_^(x y z)
> 
> expands to:
> 
> 	foo_x foo_y foo_z
> 

I had issues with just expanding the headers using -r^headers. It 
generates an hget command like (just an echo before line 98):

hget -rX-Foo: Lol -rAuthorization: Bearer Token -r Content-Type: 
multipart/form-data; boundary=HJBOUNDARY -b https://httpbin.org -P /post

where a valid hget command would be:
hget -r 'X-Foo: Lol' -r 'Authorization: Bearer Token' -r 'Content-Type: 
multipart/form-data; boundary=HJBOUNDARY' -b https://httpbin.org -P /post

so I updated with a for loop but maybe there is a better way?

Thanks for the feedback and the tips!


diff -r ac35c963f8e2 rc/bin/hpost
--- a/rc/bin/hpost	Sun Dec 13 20:23:03 2020 +0100
+++ b/rc/bin/hpost	Wed Dec 16 17:57:47 2020 +0000
@@ -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 ] headers [ -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 $1)
  	case -g;	shift; action=$1; method=mget
  	case -p;	shift; action=$1; method=mpost
  	case -m;	shift; action=$1; method=multi
@@ -95,7 +99,14 @@
  }

  if(! ~ $action ''){
-	hget=(hget $l)
+	if(~ $headers '')
+		hget=(hget $l)
+	if not
+		h=()
+		for(i in $headers)
+			h=($h -r $i)
+		hget=(hget $h $l)
+
  	$method
  	exit
  }
diff -r ac35c963f8e2 sys/man/1/hget
--- a/sys/man/1/hget	Sun Dec 13 20:23:03 2020 +0100
+++ b/sys/man/1/hget	Wed Dec 16 17:57:47 2020 +0000
@@ -38,6 +38,9 @@
  .B -m
  .I action
  ] [
+.B -r
+.I header
+] [
  .B -u
  ]
  .I url


  reply	other threads:[~2020-12-16 18:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 18:02 Julien Blanchard
2020-12-15 18:42 ` ori
2020-12-16 18:16   ` Julien Blanchard [this message]
2020-12-16 18:51     ` sirjofri
2020-12-16 19:50       ` ori
2020-12-16 21:34         ` sirjofri
2020-12-16 21:52           ` ori
2020-12-16 22:55             ` sirjofri
2020-12-16 23:13               ` Steve Simon
2020-12-17  9:33                 ` Julien Blanchard
2020-12-17 10:30                   ` Alex Musolino
2020-12-17 11:23                     ` Julien Blanchard
2020-12-18  4:35                       ` ori
2020-12-16 19:54     ` estevan.cps
2020-12-18  2:25 ` magma698hfsp273p9f

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b13de105-af36-76fd-af65-e697264ae3f7@typed-hole.org \
    --to=julien@typed-hole.org \
    --cc=9front@9front.org \
    --cc=ori@eigenstate.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).