ref: 1561f0c4ea7801fef9689387e19c77d300f98a2d
parent: f2bd1de5bdba2449f01085984483702adb833fea
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 24 16:28:48 EST 2013
webfs: preserve unicode hostname, only convert to ascii when sending over the wire we'd like to keep Url.host in unicode for factotum key lookup. only when we send the url in a request, we have to convert it to ascii.
--- a/sys/src/cmd/webfs/fs.c
+++ b/sys/src/cmd/webfs/fs.c
@@ -415,6 +415,10 @@
* so we make one up.
*/
if(u = url("/", cl->url)){+ if(r = u->host){+ u->host = smprint("%H", r);+ free(r);
+ }
if(r = smprint("%U", u)){cl->hdr = addkey(cl->hdr, "Referer", r);
free(r);
@@ -764,8 +768,8 @@
quotefmtinstall();
fmtinstall('U', Ufmt);- fmtinstall('E', Efmt); fmtinstall('H', Hfmt);+ fmtinstall('E', Efmt);srv = nil;
mtpt = "/mnt/web";
--- a/sys/src/cmd/webfs/http.c
+++ b/sys/src/cmd/webfs/http.c
@@ -389,7 +389,7 @@
fmtprint(&fmt, "Digest ");
fmtprint(&fmt, "username=\"%s\", ", ouser);
fmtprint(&fmt, "realm=\"%s\", ", realm);
- fmtprint(&fmt, "host=\"%s\", ", u->host);
+ fmtprint(&fmt, "host=\"%H\", ", u->host);
fmtprint(&fmt, "uri=\"%U\", ", ru);
fmtprint(&fmt, "nonce=\"%s\", ", nonce);
fmtprint(&fmt, "response=\"%s\"", resp);
@@ -465,7 +465,7 @@
http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
{int i, l, n, try, pid, fd, cfd, needlength, chunked, retry, nobody;
- char *s, *x, buf[8192+2], status[256], method[16];
+ char *s, *x, buf[8192+2], status[256], method[16], *host;
vlong length, offset;
Url ru, tu, *nu;
Key *k, *rhdr;
@@ -503,6 +503,7 @@
h = nil;
pid = 0;
+ host = nil;
needlength = 0;
for(try = 0; try < 12; try++){strcpy(status, "0 No status");
@@ -565,8 +566,13 @@
qunlock(qpost);
}
+ /* http requires ascii encoding of host */
+ free(host);
+ host = smprint("%H", u->host);+
if(proxy){ru = *u;
+ ru.host = host;
ru.fragment = nil;
} else {memset(&ru, 0, sizeof(tu));
@@ -573,8 +579,8 @@
ru.path = Upath(u);
ru.query = u->query;
}
- n = snprint(buf, sizeof(buf), "%s %U HTTP/1.1\r\nHost: %H%s%s\r\n",
- method, &ru, u->host, u->port ? ":" : "", u->port ? u->port : "");
+ n = snprint(buf, sizeof(buf), "%s %U HTTP/1.1\r\nHost: %s%s%s\r\n",
+ method, &ru, host, u->port ? ":" : "", u->port ? u->port : "");
if(n >= sizeof(buf)-64){ werrstr("request too large");break;
@@ -589,7 +595,7 @@
/* only scheme, host and path are relevant for cookies */
memset(&tu, 0, sizeof(tu));
tu.scheme = u->scheme;
- tu.host = u->host;
+ tu.host = host;
tu.path = Upath(u);
fprint(cfd, "%U", &tu);
for(;;){@@ -925,6 +931,7 @@
hclose(h);
freeurl(u);
+ free(host);
while(k = shdr){shdr = k->next;
--- a/sys/src/cmd/webfs/url.c
+++ b/sys/src/cmd/webfs/url.c
@@ -102,7 +102,7 @@
fmtprint(f, "@");
}
if(u->host){- fmtprint(f, strchr(u->host, ':') ? "[%s]" : "%H", u->host);
+ fmtprint(f, strchr(u->host, ':') ? "[%s]" : "%s", u->host);
if(u->port)
fmtprint(f, ":%s", u->port);
}
--
⑨