This patch fixes webfs not working on a nonstandard port for urls of the type: http://www.url.com:8080:/asdfads The count of subexpressions in the regular expression definitions in url.c was wrong. It also fixes an error in the POST code which would post more than once for an authenticated connection. I have tried this in the urls I care about, and the fixes seem not to break anything else. d Reference: /n/sources/patch/applied/webfsfixes Date: Mon Sep 29 11:40:41 CES 2008 Signed-off-by: paurea@gmail.com --- /sys/src/cmd/webfs/client.c Mon Sep 29 11:38:07 2008 +++ /sys/src/cmd/webfs/client.c Mon Sep 29 11:38:04 2008 @@ -74,9 +74,10 @@ clientbodyopen(Client *c, Req *r) { char e[ERRMAX], *next; - int i; + int i, nauth; Url *u; + nauth = 0; next = nil; for(i=0; i<=c->ctl.redirectlimit; i++){ if(c->url == nil){ @@ -103,8 +104,8 @@ respond(r, e); return; } - if (c->authenticate) - continue; + if (c->authenticate && nauth++ < 1) + continue; if(!c->redirect) break; next = c->redirect; --- /sys/src/cmd/webfs/http.c Mon Sep 29 11:38:12 2008 +++ /sys/src/cmd/webfs/http.c Mon Sep 29 11:38:09 2008 @@ -268,16 +268,24 @@ char *cookies; Ioproc *io; HttpState *hs; + char *service; if(httpdebug) fprint(2, "httpopen\n"); io = c->io; hs = emalloc(sizeof(*hs)); hs->c = c; - hs->netaddr = estrdup(netmkaddr(url->host, 0, url->scheme)); + + if(url->port) + service = url->port; + else + service = url->scheme; + hs->netaddr = estrdup(netmkaddr(url->host, 0, service)); c->aux = hs; - if(httpdebug) + if(httpdebug){ fprint(2, "dial %s\n", hs->netaddr); + fprint(2, "dial port: %s\n", url->port); + } fd = iotlsdial(io, hs->netaddr, 0, 0, 0, url->ischeme==UShttps); if(fd < 0){ Error: @@ -297,7 +305,7 @@ hs->fd = fd; if(httpdebug) fprint(2, "<- %s %s HTTP/1.0\n<- Host: %s\n", - c->havepostbody? "POST": " GET", url->http.page_spec, url->host); + c->havepostbody? "POST": "GET", url->http.page_spec, url->host); ioprint(io, fd, "%s %s HTTP/1.0\r\nHost: %s\r\n", c->havepostbody? "POST" : "GET", url->http.page_spec, url->host); if(httpdebug) @@ -331,7 +339,6 @@ if(iowrite(io, fd, c->postbody, c->npostbody) != c->npostbody) goto Error; - c->havepostbody = 0; redirect = 0; authenticate = 0; initibuf(&hs->b, io, fd); --- /sys/src/cmd/webfs/url.c Mon Sep 29 11:38:17 2008 +++ /sys/src/cmd/webfs/url.c Mon Sep 29 11:38:14 2008 @@ -170,7 +170,7 @@ [REauthority] "^(((" USERINFO_2 "*)@)?(((\\[[^\\]@]+\\])|([^:\\[@]+))(:([0-9]*))?)?)?$", nil, 0, /* |----user info-----| |--------host----------------| |-port-| */ - { 2, 7, 12, }, + { 3, 7, 11, }, [REhost] "^(([a-zA-Z0-9\\-.]+)|(\\[([a-fA-F0-9.:]+)\\]))$", nil, 0, @@ -667,6 +667,8 @@ { Resub m[MaxResub]; Retab *t; + char *host; + char *userinfo; if(su->authority.s == nil) return 0; @@ -688,6 +690,15 @@ if(m[t->ind[2]].sp) u->port = estredup(m[t->ind[2]].sp, m[t->ind[2]].ep); + + if(urldebug > 0){ + userinfo = estredup(m[t->ind[0]].sp, m[t->ind[0]].ep); + host = estredup(m[t->ind[1]].sp, m[t->ind[1]].ep); + fprint(2, "port: %q, authority %q\n", u->port, u->authority); + fprint(2, "host %q, userinfo %q\n", host, userinfo); + free(host); + free(userinfo); + } return 0; }