9front - general discussion about 9front
 help / color / mirror / Atom feed
From: telephil9@gmail.com
To: 9front@9front.org
Subject: [9front] [PATCH] webfs: add 'headers' file
Date: Sun, 10 Jan 2021 19:32:06 +0100	[thread overview]
Message-ID: <92666EC50A56FDFFA061325E323A4FE3@gmail.com> (raw)

Hi,

Following patch adds a 'headers' file containing the full list of response headers 
along with their values (each line is Header: value).
I need this for netsurf which expects response headers prior to processing a request, and the
current webfs mechanism is not really convenient to work with in this case.

===
diff -r f020e57da8d6 sys/src/cmd/webfs/fs.c
--- a/sys/src/cmd/webfs/fs.c	Thu Dec 17 20:26:38 2020 -0800
+++ b/sys/src/cmd/webfs/fs.c	Sun Jan 10 19:24:24 2021 +0100
@@ -42,6 +42,7 @@
 			Qctl,
 			Qbody,
 			Qpost,
+			Qheaders,
 			Qparsed,
 				Qurl,
 				Qurlschm,
@@ -63,6 +64,7 @@
 			"ctl",
 			"body",
 			"postbody",
+			"headers",
 			"parsed",
 				"url",
 				"scheme",
@@ -293,6 +295,14 @@
 		}
 	} else {
 		for(i=f->level+1; i < nelem(nametab); i++){
+			if(i == Qheaders && f->client && f->client->qbody){
+				Key *k;
+
+				for(k = f->client->qbody->hdr; k; k = k->next){
+					f->key = addkey(f->key, k->key, k->val);
+				}
+				break;
+			}
 			if(nametab[i]){
 				if(strcmp(name, nametab[i]) == 0)
 					break;
@@ -479,8 +489,10 @@
 static void
 fsread(Req *r)
 {
-	char buf[1024];
+	char buf[2048];
 	Webfid *f;
+	Key *k;
+	int n;
 
 	f = r->fid->aux;
 	switch(f->level){
@@ -505,6 +517,17 @@
 	case Qctl:
 		snprint(buf, sizeof(buf), "%d\n", CLIENTID(f->client));
 		goto String;
+	case Qheaders:
+		n = 0;
+		for(k = f->key; k != nil; k = k->next){
+			n += snprint(buf+n, sizeof(buf)-n, "%s: %s\n", k->key, k->val);
+			if(n >= sizeof(buf)){
+				n = sizeof(buf)-1;
+				break;
+			}
+		}
+		buf[n] = 0;
+		goto String;
 	case Qheader:
 		snprint(buf, sizeof(buf), "%s", f->key->val);
 		goto String;
@@ -703,6 +726,7 @@
 fsdestroyfid(Fid *fid)
 {
 	Webfid *f;
+	Key *k, *d;
 
 	if(f = fid->aux){
 		fid->aux = nil;
@@ -714,8 +738,13 @@
 			}
 			bufree(f->buq);
 		}
-		if(f->key)
-			free(f->key);
+		if(f->key){
+			for(k = f->key; k != nil;){
+				d = k;
+				k = k->next;
+				free(d);
+			}
+		}
 		freeclient(f->client);
 		free(f);
 	}
===

Man page:
===
diff -r f020e57da8d6 sys/man/4/webfs
--- a/sys/man/4/webfs	Thu Dec 17 20:26:38 2020 -0800
+++ b/sys/man/4/webfs	Sun Jan 10 19:30:48 2021 +0100
@@ -165,6 +165,11 @@
 .B parsed
 directory will change to the final destination.
 .PP
+The
+.B headers
+file gives the full list of headers along with their values,
+one per line.
+.PP
 The resulting data may be read from
 .B body
 as it arrives.
===

--phil

             reply	other threads:[~2021-01-10 19:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-10 18:32 telephil9 [this message]
2021-01-10 19:28 ` ori
2021-01-10 19:51   ` ori
2021-01-10 20:30     ` Lyndon Nerenberg
2021-01-10 21:11       ` ori
2021-01-10 22:29         ` Lyndon Nerenberg
2021-01-11  0:50           ` hiro
2021-01-10 21:16       ` Steve Simon
2021-01-11 17:13         ` ori
2021-01-11 21:53           ` cinap_lenrek

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=92666EC50A56FDFFA061325E323A4FE3@gmail.com \
    --to=telephil9@gmail.com \
    --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).