From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by ewsd; Thu Jan 16 12:24:09 EST 2020 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 513CD21F1E for <9front@9front.org>; Thu, 16 Jan 2020 12:24:07 -0500 (EST) Received: from imap35 ([10.202.2.85]) by compute1.internal (MEProxy); Thu, 16 Jan 2020 12:24:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type; s=fm2; bh=xfM8kUrFA7KQ8BkIjHeo8/M5NOFi1zZ 5SqgVHXf994A=; b=aL5gU4ADnFNHOHZRjF9B74uA4LLSNOF0makwijELgPqXG0i UPcMfQ3CPTl5taPZ6d3LX1uV5YWOWaFaj8llNqMH0S3Zf7qEwKEDXCalPyiWio8W M/T5YkUF0nMjz8KuB501R9l9Ls1yl2vN3tpcs9IkvM1XVs5lcRmaWQjuSRs84GDN JUU4H8b8OT8RT5OyndZxTWOzyE/ggqCcORSO2z+Ykjv9rjWRLFIrou0DMwepc6Dv i1Lkvlxuhd2aiCE5mnzVA9t2tGx3kA0BiRhkKaF1Q8/uBPrPwywHnoGOVZzfameu MbhwfTRHoVDzof++fQAid0HWH5EHsDhP+a6Fbuw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=xfM8kU rFA7KQ8BkIjHeo8/M5NOFi1zZ5SqgVHXf994A=; b=n/pg1SP2C3FfskNaHfAPUU 4/g3sI6TRiQz5nfAv+cFisC2kllLtWE7VNYBHJbIaDtuV+XfWnXvOS5cS1TDOeX1 e0Hjly2rnl/If7E5p8Q3vF59XCE7VSmKcm5YJqrHEahGVqGguXKX/VYgY1xJ7Wfe T3ub95i4CDPhnhx991exBYcT31AJxQ9PT9hJXPpKSnh75sBFPRSsM8H1UFOX/uFK XkYiTrzUzkoC4MgHOPfnuZ7g7jJwmsZSkhyZsiKIeKOW3b5yNScNigWA9wpIZvSK KMcgYYn5BqqrThO0C13YVs/22o/5wYqJnrX+EbwGQzCqw6zG8TadIa3ohPF4gi2A == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrtdehgdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesthdtre dtreertdenucfhrhhomhepfdfgthhhrghnucfirghruggvnhgvrhdfuceovggvkhgvvgeh jeesfhgrshhtmhgrihhlrdhfmheqnecurfgrrhgrmhepmhgrihhlfhhrohhmpegvvghkvg gvheejsehfrghsthhmrghilhdrfhhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1533214C0596; Thu, 16 Jan 2020 12:24:06 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-754-g09d1619-fmstable-20200113v1 Mime-Version: 1.0 Message-Id: In-Reply-To: <5F78518AF28D01DD965738D7D8D4CF45@musolino.id.au> References: <5F78518AF28D01DD965738D7D8D4CF45@musolino.id.au> Date: Thu, 16 Jan 2020 17:23:46 +0000 From: "Ethan Gardener" To: 9front@9front.org Subject: Re: [9front] Content-range support for rc-httpd(8) Content-Type: text/plain List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: transactional plugin event component Looks good to me, with the caveat that I haven't looked up how it's supposed to work, nor tested it. I'm not sure why it uses both hoc and bc, but that's a very minor point. On Tue, Jan 7, 2020, at 7:15 AM, Alex Musolino wrote: > Some time ago I had a crack at implementing content-range support in > rc-httpd(8). A previous email regarding a dissatisfied (non-)customer > prompted me to make the following patch public. It works for my > purposes and may serve as a starting point for something that could > eventually be included in 9front. > > No refunds. > > diff -r 5423b63716e7 rc/bin/rc-httpd/handlers/serve-static > --- a/rc/bin/rc-httpd/handlers/serve-static Tue Jan 07 17:28:59 2020 +1030 > +++ b/rc/bin/rc-httpd/handlers/serve-static Tue Jan 07 18:13:26 2020 +1100 > @@ -16,7 +16,6 @@ > error 503 > exit > } > -do_log 200 > switch($full_path){ > case *.html *.htm > type=text/html > @@ -36,8 +35,14 @@ > if(~ $type text/*) > type=$type^'; charset=utf-8' > max_age=3600 # 1 hour > +if(! ~ $#CONTENT_RANGE 0){ > + . serve-static-range > + exit > +} > +do_log 200 > echo 'HTTP/1.1 200 OK'^$cr > emit_extra_headers > +echo 'Accept-ranges: bytes'^$cr > echo 'Content-type: '^$type^$cr > echo 'Content-length: '^`{ls -l $full_path | awk '{print $6}'}^$cr > echo 'Cache-control: max-age='^$max_age^$cr > diff -r 5423b63716e7 rc/bin/rc-httpd/handlers/serve-static-range > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/rc/bin/rc-httpd/handlers/serve-static-range Tue Jan 07 18:13:26 2020 +1100 > @@ -0,0 +1,46 @@ > +#!/bin/rc > + > +fn range{ > + syscall seek 0 $1 0 > + length=$2 > + while(! ~ $length 0){ > + switch(`{echo $length^' >= '^$3 | hoc}){ > + case 1 > + read -c $3 > + length=`{echo $length - $3 | bc} > + case 0 > + read -c $length > + length=0 > + } > + } > +} > + > +chunk=512000 > +total=`{du -n $full_path} > +total=$total(1) > + > +switch($#CONTENT_RANGE){ > +case 2 > + start=$CONTENT_RANGE(1) > + end=$CONTENT_RANGE(2) > +case 1 > + start=$CONTENT_RANGE(1) > + end=`{echo $start + $chunk - 1 | bc} > +case * > + error 416 > + exit > +} > + > +end=`{echo 'if('$end'>='$total'){print '$total'-1}else{print '$end'}' | hoc} > +length=`{echo $end - $start + 1 | bc} > + > +do_log 206 > +echo 'HTTP/1.1 206 Partial Content'^$cr > +emit_extra_headers > +echo 'Accept-ranges: bytes'^$cr > +echo 'Content-type: '^$type^$cr > +echo 'Cache-control: max-age='^$max_age^$cr > +echo 'Content-range: bytes '^$start^-^$end^/^$total^$cr > +echo 'Content-length: '^$length^$cr > +echo $cr > +range $start $length $chunk <$full_path > diff -r 5423b63716e7 rc/bin/rc-httpd/rc-httpd > --- a/rc/bin/rc-httpd/rc-httpd Tue Jan 07 17:28:59 2020 +1030 > +++ b/rc/bin/rc-httpd/rc-httpd Tue Jan 07 18:13:26 2020 +1100 > @@ -51,6 +51,8 @@ > HTTP_REFERER=$line(2) > case user-agent: > HTTP_USER_AGENT=`{echo $line | sed 's;[^:]+:[ ]+;;'} > + case range: > + CONTENT_RANGE=`{echo $line(2) | sed -e 's/bytes=//' -e 's/-/ /'} > case content-length: > CONTENT_LENGTH=$line(2) > case content-type: > > -- > Cheers, > Alex Musolino >