From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30935 invoked from network); 15 Dec 2020 18:43:24 -0000 Received: from ewsd.inri.net (107.191.116.128) by inbox.vuxu.org with ESMTPUTF8; 15 Dec 2020 18:43:24 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by ewsd; Tue Dec 15 13:42:47 -0500 2020 Received: from abbatoir.fios-router.home (pool-74-101-2-6.nycmny.fios.verizon.net [74.101.2.6]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 0c34e5fd (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO); Tue, 15 Dec 2020 10:42:39 -0800 (PST) Message-ID: To: julien@typed-hole.org To: 9front@9front.org Date: Tue, 15 Dec 2020 10:42:37 -0800 From: ori@eigenstate.org In-Reply-To: <5bae97d5-c808-7faf-c0f3-2dfcdfabbfa1@typed-hole.org> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: non-blocking WEB2.0 over SQL API-scale interface Subject: Re: [9front] [PATCH] Update hpost to use -r header like hget Reply-To: 9front@9front.org Precedence: bulk Quoth Julien Blanchard : > Hello, > This is a small update to hpost which allows the use of a -r header > option just like in hget. I had the need when trying to push a file to > an API which also needed an authorization header. > It's the first time I write some not trivial rc script so maybe there is > a better way to add this option. After quite some testing it looks like > it works at least :) Thanks for the patch. just a few revisions: > > Cheers, > julienxx > > > > diff -r ac35c963f8e2 rc/bin/hpost > --- a/rc/bin/hpost Sun Dec 13 20:23:03 2020 +0100 > +++ b/rc/bin/hpost Tue Dec 15 17:45:26 2020 +0000 > @@ -1,12 +1,13 @@ > #!/bin/rc > rfork e > url=() > +header=() 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. > 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 +15,7 @@ > switch($1){ > case -l; l=($l $1) > case -u; shift; url=$1 > + case -r; shift; header=$1 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