From: igor@9lab.org
To: 9front@9front.org
Cc: igor@9lab.org
Subject: [9front] rc-httpd: fold two sed calls into one when computing location
Date: Sat, 30 Oct 2021 01:09:32 +0200 [thread overview]
Message-ID: <9A8A46C850B5E66C75A55B554E26D0E3@9lab.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 1356 bytes --]
At line /rc/bin/rc-httpd/rc-httpd:77 the variable `location` is
computed as follows:
…
location=`{echo $REQUEST_URI | sed 's;\?.*;;'}
location=`{echo $location | sed '
s;[^/]+/\.\./;/;g
s;/\./;/;g
s;//+;/;g
'}
…
Does anyone know why `sed` is used twice to derive the variable
`location`? In other words, why isn't `location` computed using
a single invocation of `sed` like this:
…
location=`{echo $REQUEST_URI | sed '
s;\?.*;;
s;[^/]+/\.\./;/;g
s;/\./;/;g
s;//+;/;g
'}
…
The result should be the same, or am I missing something? The
advantage of this change is one less invocation of `sed` for each http
request.
Here an the git/importable patch:
<snip>
From: Igor Böhm <igor@9lab.org>
Date: Fri, 29 Oct 2021 22:59:06 +0000
Subject: [PATCH] rc-httpd: fold two sed calls into one when computing location
---
diff ee31c7808087c24b268bb5700b6d695c1bae0cd8 76990597f21f5ec3972403e8afbc18dba80ddabe
--- a/rc/bin/rc-httpd/rc-httpd Mon Oct 18 01:35:37 2021
+++ b/rc/bin/rc-httpd/rc-httpd Sat Oct 30 00:59:06 2021
@@ -74,8 +74,8 @@
}
QUERY_STRING=`{echo $REQUEST_URI | sed 's;[^?]*\??;;'}
params=`{echo $QUERY_STRING | sed 's;\+; ;g'}
-location=`{echo $REQUEST_URI | sed 's;\?.*;;'}
-location=`{echo $location | sed '
+location=`{echo $REQUEST_URI | sed '
+ s;\?.*;;
s;[^/]+/\.\./;/;g
s;/\./;/;g
s;//+;/;g
</snap>
Cheers,
Igor
[-- Attachment #2: rc-httpd.patch --]
[-- Type: text/plain, Size: 654 bytes --]
From: Igor Böhm <igor@9lab.org>
Date: Fri, 29 Oct 2021 22:59:06 +0000
Subject: [PATCH] rc-httpd: fold two sed calls into one when computing location
---
diff ee31c7808087c24b268bb5700b6d695c1bae0cd8 76990597f21f5ec3972403e8afbc18dba80ddabe
--- a/rc/bin/rc-httpd/rc-httpd Mon Oct 18 01:35:37 2021
+++ b/rc/bin/rc-httpd/rc-httpd Sat Oct 30 00:59:06 2021
@@ -74,8 +74,8 @@
}
QUERY_STRING=`{echo $REQUEST_URI | sed 's;[^?]*\??;;'}
params=`{echo $QUERY_STRING | sed 's;\+; ;g'}
-location=`{echo $REQUEST_URI | sed 's;\?.*;;'}
-location=`{echo $location | sed '
+location=`{echo $REQUEST_URI | sed '
+ s;\?.*;;
s;[^/]+/\.\./;/;g
s;/\./;/;g
s;//+;/;g
reply other threads:[~2021-10-29 23:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=9A8A46C850B5E66C75A55B554E26D0E3@9lab.org \
--to=igor@9lab.org \
--cc=9front@9front.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).