diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2013-11-24 21:28:48 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2013-11-24 21:28:48 +0100 |
commit | 1561f0c4ea7801fef9689387e19c77d300f98a2d (patch) | |
tree | 66cdc883230c4beb8729e76e8fde3d3fc3f6720c | |
parent | f2bd1de5bdba2449f01085984483702adb833fea (diff) | |
download | plan9front-1561f0c4ea7801fef9689387e19c77d300f98a2d.tar.xz |
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.
-rw-r--r-- | sys/src/cmd/webfs/fs.c | 6 | ||||
-rw-r--r-- | sys/src/cmd/webfs/http.c | 17 | ||||
-rw-r--r-- | sys/src/cmd/webfs/url.c | 2 |
3 files changed, 18 insertions, 7 deletions
diff --git a/sys/src/cmd/webfs/fs.c b/sys/src/cmd/webfs/fs.c index 21d6f361e..8aedbff5c 100644 --- a/sys/src/cmd/webfs/fs.c +++ b/sys/src/cmd/webfs/fs.c @@ -415,6 +415,10 @@ fsopen(Req *r) * 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 @@ main(int argc, char *argv[]) quotefmtinstall(); fmtinstall('U', Ufmt); - fmtinstall('E', Efmt); fmtinstall('H', Hfmt); + fmtinstall('E', Efmt); srv = nil; mtpt = "/mnt/web"; diff --git a/sys/src/cmd/webfs/http.c b/sys/src/cmd/webfs/http.c index 3e023be4d..480b3372d 100644 --- a/sys/src/cmd/webfs/http.c +++ b/sys/src/cmd/webfs/http.c @@ -389,7 +389,7 @@ authenticate(Url *u, Url *ru, char *method, char *s) 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 @@ void 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 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost) h = nil; pid = 0; + host = nil; needlength = 0; for(try = 0; try < 12; try++){ strcpy(status, "0 No status"); @@ -565,16 +566,21 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost) 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)); 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 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost) /* 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 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost) hclose(h); freeurl(u); + free(host); while(k = shdr){ shdr = k->next; diff --git a/sys/src/cmd/webfs/url.c b/sys/src/cmd/webfs/url.c index ebd538dbf..7ced4805d 100644 --- a/sys/src/cmd/webfs/url.c +++ b/sys/src/cmd/webfs/url.c @@ -102,7 +102,7 @@ Ufmt(Fmt *f) 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); } |