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.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,NICE_REPLY_A,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28245 invoked from network); 16 Dec 2020 18:17:04 -0000 Received: from ewsd.inri.net (107.191.116.128) by inbox.vuxu.org with ESMTPUTF8; 16 Dec 2020 18:17:04 -0000 Received: from mail.typed-hole.org ([199.247.9.36]) by ewsd; Wed Dec 16 13:16:29 -0500 2020 Received: from mail.typed-hole.org (localhost [127.0.0.1]) by mail.typed-hole.org (OpenSMTPD) with ESMTP id 22dd1df4; Wed, 16 Dec 2020 18:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=typed-hole.org; h=subject :to:references:from:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; s=20190925; bh=6eijvFXx sUXhNOP+ds2izOz0rys=; b=okOUk8zVlYseLfjXfvAjPldNWzii5pAgT31BnNNN Ugpt/n+D9+ttwKyY+LLIWcTKFq411voZMJC5pdyowZuJNa4i2OtraR6O34LqmA9a /TUL1WSri42MikyO0XYKGmLGIbW2NiGJ+lzxoG6oFs4AIIxYJrel9CJOnd3My7vW htk8lZUts9YglfgBJfCjj41IWf+IRFM9D07vbPaZ0OdpOBQ1SknOp/dWt3GYeE2t pTV+q8paUZskP4hMQDCYSvjD6BmHHHNPATYjVQ2yQ0LF7y3VminrvBSNlTkfhd6L zLhp+FpXk3ZIdIigbSdr0LWLpYlTRP8bqgQKHbT97Pxg8A== DomainKey-Signature: a=rsa-sha1; c=nofws; d=typed-hole.org; h=subject:to :references:from:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; q=dns; s=20190925; b=EI n64xJCk2n4N0SeM3yDrFhu73ng0l5175k7nN1saHEikDL80F13o5CvqQVcl0ITmY zYyWyUHkJCFXh3/jAylieli8UtgUahVgqqLSbbLn1Jmt7IHFUwfrEDGZXYn/3DGj FhGp1qXKBrzvMabg1k4C7J6k+pjw54G7bZLf5xgVBcaUZWCAn1K70jsQUZuZSVhL tYAeyZujXp7Il0ruL+VDoB7QC4zTmW77giYjaFdwkwlxj77B4mPQpS46gakVd8iy gRCXDx4C2Es9qQVAgYZXco9rrHSUjGs5QXMjS3Vyrlfdfm706Sezk8lS8RCO5yia WlC9njqRInzbeOZkLUpw== Received: from [192.168.0.11] (87-231-19-8.rev.numericable.fr [87.231.19.8]) by mail.typed-hole.org (OpenSMTPD) with ESMTPSA id 99998a06 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Wed, 16 Dec 2020 18:16:23 +0000 (UTC) To: ori@eigenstate.org, 9front@9front.org References: From: Julien Blanchard Message-ID: Date: Wed, 16 Dec 2020 19:16:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: stable engine Subject: Re: [9front] [PATCH] Update hpost to use -r header like hget Reply-To: 9front@9front.org Precedence: bulk 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