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 /sys/src/cmd/webfs/http.c | |
parent | f2bd1de5bdba2449f01085984483702adb833fea (diff) |
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.
Diffstat (limited to 'sys/src/cmd/webfs/http.c')
-rw-r--r-- | sys/src/cmd/webfs/http.c | 17 |
1 files changed, 12 insertions, 5 deletions
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; |