From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 Date: Tue, 21 Jan 2014 22:46:30 -0500 Message-ID: From: cherry To: werc9@googlegroups.com, Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=001a11c137e062f96004f086f8e1 Subject: [9fans] Things about werc + Plan 9 httpd Topicbox-Message-UUID: b42d51d2-ead8-11e9-9d60-3106f5b1d025 --001a11c137e062f96004f086f8e1 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hello, As I recently played werc on Plan 9, I would like to share a couple of things I found. First, in the Docs page ( http://werc.cat-v.org/docs/web-server-setup/plan-9-httpd), it says > you will need to replace the =91%($=93extraHeaders%)=92 in lib/headers.tp= l with =91% echo $"extraHeaders=92 no clue why. The reason is %(...%) invokes "echo -n", and when the variable is empty (in many cases $extraHeaders is), it calls write() with zero length, which, if writes to a pipe, causes the other end of the pipe read()'s zero byte (as pipe(3) says, write boundary is preserved), and it may think it's got to the end. For example, cat, /sys/src/cmd/cat.c:10 while((n=3Dread(f, buf, (long)sizeof buf))>0) $=93extraHeaders is used in bin/werc.rc:140 template $headers $master_template | awk_buffer which also suffers the same problem. I have played many different ways to work around it, and my current solution (I believe covering all cases) is to wrap echo as fn echo { builtin echo $* | cat } so when it is echoing nothing, "cat" will consume the zero-length write(). Any comment or idea? I don't have p9p so I don't know why there is no such problem. Probably unix's pipe implemented differently. Second, in the same Docs page, the werc-wrapper's arguments seem not matched with httpd's magic. Is it outdated? Or I missed anything? The following works for me: SERVER_NAME=3D$*(2) REQUEST_URI=3D`{echo $*(22)} if(~ $#REQUEST_URI 0) REQUEST_URI=3D/ REQUEST_METHOD=3D$*(20) PLAN9=3D/ Another thing is about remapping the root directory. Httpd does not handle it, so we put all stuff into a sub directory, but many werc generated links are still pointing to something under the root, e.g. the side-bar, and even css. Certainly a way is to hack werc. My alternative approach is generating rewriting rules mapping every first-level directories, putting it into a script starting httpd, like, echo /w @/magic/werc-wrap > /tmp/rewrite echo / @/w >> /tmp/rewrite for(i in `{ls -p $sitedir}) echo /$i @/w/$i >> /tmp/rewrite bind /tmp/rewrite /sys/lib/httpd.rewrite Kill httpd | rc ip/httpd/httpd A problem is adding new stuff to the root requires a restart of httpd, but this happens probably not very often. Hope this is useful, and sorry for a long email. Thanks, - cherry --001a11c137e062f96004f086f8e1 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
Hello,

As I recently played werc on Plan = 9, I would like to share a couple of things I found.

First, in= the Docs page (http://werc.cat-v.org/docs/web-server-setup/plan-9-httpd), it= says

> you will need to replace the =91%($=93extraHeaders%)=92 in lib/headers.tpl with =91% echo $"extraHeaders=92 no clue why.

The reason is %(...%) invokes &q= uot;echo -n", and when the variable is empty (in many cases $extraHead= ers is), it calls write() with zero length, which, if writes to a pipe, cau= ses the other end of the pipe read()'s zero byte (as pipe(3) says, writ= e boundary is preserved), and it may think it's got to the end. For exa= mple, cat, /sys/src/cmd/cat.c:10

=A0=A0=A0 while((n=3Dread(f, buf, (long)sizeof buf))>0)

$=93extraHeaders is used in bin/werc.rc:140

=A0=A0=A0 template= $headers $master_template | awk_buffer

which also suffers the same = problem. I have played many different ways to work around it, and my curren= t solution (I believe covering all cases) is to wrap echo as

fn echo { builtin echo $* | cat }

so when it is echoing nothing,= "cat" will consume the zero-length write(). Any comment or idea?= I don't have p9p so I don't know why there is no such problem. Pro= bably unix's pipe implemented differently.


Second, in the same Docs page, the werc-wrapper's arguments see= m not matched with httpd's magic. Is it outdated? Or I missed anything?= The following works for me:

SERVER_NAME=3D$*(2)
REQUEST_URI=3D`{= echo $*(22)}
if(~ $#REQUEST_URI 0)
=A0=A0=A0 REQUEST_URI=3D/
REQUEST_METHOD=3D$*(2= 0)
PLAN9=3D/


Another thing is about remapping the root direct= ory. Httpd does not handle it, so we put all stuff into a sub directory, bu= t many werc generated links are still pointing to something under the root,= e.g. the side-bar, and even css. Certainly a way is to hack werc. My alter= native approach is generating rewriting rules mapping every first-level dir= ectories, putting it into a script starting httpd, like,

=A0=A0=A0 echo /w @/magic/werc-wrap > /tmp/rewrite
=A0=A0=A0 echo= / @/w >> /tmp/rewrite
=A0=A0=A0 for(i in `{ls -p $sitedir})
= =A0=A0=A0 =A0=A0=A0 echo /$i @/w/$i >> /tmp/rewrite

=A0=A0=A0 = bind /tmp/rewrite /sys/lib/httpd.rewrite

=A0=A0=A0 Kill httpd | rc
=A0=A0=A0 ip/httpd/httpd

A problem = is adding new stuff to the root requires a restart of httpd, but this happe= ns probably not very often.

Hope this is useful, and sorr= y for a long email.

Thanks,
- cherry

--001a11c137e062f96004f086f8e1--