webfs: bracket literal ipv6 host in "Host:" header

This commit is contained in:
cinap_lenrek 2019-03-23 00:49:07 +01:00
parent 1e97adc86b
commit 151039caf0
4 changed files with 14 additions and 3 deletions

View file

@ -15,10 +15,12 @@ char* unquote(char *s, char **ps);
#pragma varargck type "U" Url*
#pragma varargck type "E" Str2
#pragma varargck type "N" char*
#pragma varargck type "]" char*
int Efmt(Fmt*);
int Nfmt(Fmt*);
int Ufmt(Fmt*);
int Mfmt(Fmt*);
char* Upath(Url *);
Url* url(char *s, Url *b);
Url* saneurl(Url *u);

View file

@ -766,6 +766,7 @@ main(int argc, char *argv[])
quotefmtinstall();
fmtinstall('U', Ufmt);
fmtinstall('N', Nfmt);
fmtinstall(']', Mfmt);
fmtinstall('E', Efmt);
fmtinstall('[', encodefmt);
fmtinstall('H', encodefmt);

View file

@ -637,7 +637,7 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
ru.path = Upath(u);
ru.query = u->query;
}
n = snprint(buf, sizeof(buf), "%s %U HTTP/1.1\r\nHost: %s%s%s\r\n",
n = snprint(buf, sizeof(buf), "%s %U HTTP/1.1\r\nHost: %]%s%s\r\n",
method, &ru, host, u->port ? ":" : "", u->port ? u->port : "");
if(n >= sizeof(buf)-64){
werrstr("request too large");
@ -649,7 +649,7 @@ http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost)
break;
}
if(h->tunnel){
n = snprint(buf, sizeof(buf), "CONNECT %s:%s HTTP/1.1\r\nHost: %s:%s\r\n",
n = snprint(buf, sizeof(buf), "CONNECT %]:%s HTTP/1.1\r\nHost: %]:%s\r\n",
host, u->port ? u->port : "443",
host, u->port ? u->port : "443");
}

View file

@ -82,6 +82,14 @@ Nfmt(Fmt *f)
return 0;
}
int
Mfmt(Fmt *f)
{
char *s = va_arg(f->args, char*);
fmtprint(f, (*s != '[' && strchr(s, ':') != nil)? "[%s]" : "%s", s);
return 0;
}
int
Ufmt(Fmt *f)
{
@ -101,7 +109,7 @@ Ufmt(Fmt *f)
fmtprint(f, "@");
}
if(u->host){
fmtprint(f, strchr(u->host, ':') ? "[%s]" : "%s", u->host);
fmtprint(f, "%]", u->host);
if(u->port)
fmtprint(f, ":%s", u->port);
}