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.
This commit is contained in:
parent
f2bd1de5bd
commit
1561f0c4ea
3 changed files with 18 additions and 7 deletions
|
@ -415,6 +415,10 @@ fsopen(Req *r)
|
||||||
* so we make one up.
|
* so we make one up.
|
||||||
*/
|
*/
|
||||||
if(u = url("/", cl->url)){
|
if(u = url("/", cl->url)){
|
||||||
|
if(r = u->host){
|
||||||
|
u->host = smprint("%H", r);
|
||||||
|
free(r);
|
||||||
|
}
|
||||||
if(r = smprint("%U", u)){
|
if(r = smprint("%U", u)){
|
||||||
cl->hdr = addkey(cl->hdr, "Referer", r);
|
cl->hdr = addkey(cl->hdr, "Referer", r);
|
||||||
free(r);
|
free(r);
|
||||||
|
@ -764,8 +768,8 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
quotefmtinstall();
|
quotefmtinstall();
|
||||||
fmtinstall('U', Ufmt);
|
fmtinstall('U', Ufmt);
|
||||||
fmtinstall('E', Efmt);
|
|
||||||
fmtinstall('H', Hfmt);
|
fmtinstall('H', Hfmt);
|
||||||
|
fmtinstall('E', Efmt);
|
||||||
|
|
||||||
srv = nil;
|
srv = nil;
|
||||||
mtpt = "/mnt/web";
|
mtpt = "/mnt/web";
|
||||||
|
|
|
@ -389,7 +389,7 @@ authenticate(Url *u, Url *ru, char *method, char *s)
|
||||||
fmtprint(&fmt, "Digest ");
|
fmtprint(&fmt, "Digest ");
|
||||||
fmtprint(&fmt, "username=\"%s\", ", ouser);
|
fmtprint(&fmt, "username=\"%s\", ", ouser);
|
||||||
fmtprint(&fmt, "realm=\"%s\", ", realm);
|
fmtprint(&fmt, "realm=\"%s\", ", realm);
|
||||||
fmtprint(&fmt, "host=\"%s\", ", u->host);
|
fmtprint(&fmt, "host=\"%H\", ", u->host);
|
||||||
fmtprint(&fmt, "uri=\"%U\", ", ru);
|
fmtprint(&fmt, "uri=\"%U\", ", ru);
|
||||||
fmtprint(&fmt, "nonce=\"%s\", ", nonce);
|
fmtprint(&fmt, "nonce=\"%s\", ", nonce);
|
||||||
fmtprint(&fmt, "response=\"%s\"", resp);
|
fmtprint(&fmt, "response=\"%s\"", resp);
|
||||||
|
@ -465,7 +465,7 @@ void
|
||||||
http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
|
http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
|
||||||
{
|
{
|
||||||
int i, l, n, try, pid, fd, cfd, needlength, chunked, retry, nobody;
|
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;
|
vlong length, offset;
|
||||||
Url ru, tu, *nu;
|
Url ru, tu, *nu;
|
||||||
Key *k, *rhdr;
|
Key *k, *rhdr;
|
||||||
|
@ -503,6 +503,7 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
|
||||||
|
|
||||||
h = nil;
|
h = nil;
|
||||||
pid = 0;
|
pid = 0;
|
||||||
|
host = nil;
|
||||||
needlength = 0;
|
needlength = 0;
|
||||||
for(try = 0; try < 12; try++){
|
for(try = 0; try < 12; try++){
|
||||||
strcpy(status, "0 No status");
|
strcpy(status, "0 No status");
|
||||||
|
@ -565,16 +566,21 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
|
||||||
qunlock(qpost);
|
qunlock(qpost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* http requires ascii encoding of host */
|
||||||
|
free(host);
|
||||||
|
host = smprint("%H", u->host);
|
||||||
|
|
||||||
if(proxy){
|
if(proxy){
|
||||||
ru = *u;
|
ru = *u;
|
||||||
|
ru.host = host;
|
||||||
ru.fragment = nil;
|
ru.fragment = nil;
|
||||||
} else {
|
} else {
|
||||||
memset(&ru, 0, sizeof(tu));
|
memset(&ru, 0, sizeof(tu));
|
||||||
ru.path = Upath(u);
|
ru.path = Upath(u);
|
||||||
ru.query = u->query;
|
ru.query = u->query;
|
||||||
}
|
}
|
||||||
n = snprint(buf, sizeof(buf), "%s %U HTTP/1.1\r\nHost: %H%s%s\r\n",
|
n = snprint(buf, sizeof(buf), "%s %U HTTP/1.1\r\nHost: %s%s%s\r\n",
|
||||||
method, &ru, u->host, u->port ? ":" : "", u->port ? u->port : "");
|
method, &ru, host, u->port ? ":" : "", u->port ? u->port : "");
|
||||||
if(n >= sizeof(buf)-64){
|
if(n >= sizeof(buf)-64){
|
||||||
werrstr("request too large");
|
werrstr("request too large");
|
||||||
break;
|
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 */
|
/* only scheme, host and path are relevant for cookies */
|
||||||
memset(&tu, 0, sizeof(tu));
|
memset(&tu, 0, sizeof(tu));
|
||||||
tu.scheme = u->scheme;
|
tu.scheme = u->scheme;
|
||||||
tu.host = u->host;
|
tu.host = host;
|
||||||
tu.path = Upath(u);
|
tu.path = Upath(u);
|
||||||
fprint(cfd, "%U", &tu);
|
fprint(cfd, "%U", &tu);
|
||||||
for(;;){
|
for(;;){
|
||||||
|
@ -925,6 +931,7 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
|
||||||
|
|
||||||
hclose(h);
|
hclose(h);
|
||||||
freeurl(u);
|
freeurl(u);
|
||||||
|
free(host);
|
||||||
|
|
||||||
while(k = shdr){
|
while(k = shdr){
|
||||||
shdr = k->next;
|
shdr = k->next;
|
||||||
|
|
|
@ -102,7 +102,7 @@ Ufmt(Fmt *f)
|
||||||
fmtprint(f, "@");
|
fmtprint(f, "@");
|
||||||
}
|
}
|
||||||
if(u->host){
|
if(u->host){
|
||||||
fmtprint(f, strchr(u->host, ':') ? "[%s]" : "%H", u->host);
|
fmtprint(f, strchr(u->host, ':') ? "[%s]" : "%s", u->host);
|
||||||
if(u->port)
|
if(u->port)
|
||||||
fmtprint(f, ":%s", u->port);
|
fmtprint(f, ":%s", u->port);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue