I think we should just follow the 301. OK?
diff --git netproc.c netproc.c index 26033a3fc3c..14da5a8c1a9 100644 --- netproc.c +++ netproc.c @@ -180,15 +180,18 @@ nreq(struct conn *c, const char *addr) { struct httpget *g; struct source src[MAX_SERVERS_DNS]; + struct httphead *st; char *host, *path; short port; size_t srcsz; ssize_t ssz; long code; + int redirects = 0; if ((host = url2host(addr, &port, &path)) == NULL) return -1; +again: if ((ssz = urlresolve(c->dfd, host, src)) < 0) { free(host); free(path); @@ -202,6 +205,28 @@ nreq(struct conn *c, const char *addr) if (g == NULL) return -1; + if (g->code == 301) { + redirects++; + if (redirects > 3) { + warnx("too many redirects"); + http_get_free(g); + return -1; + } + + if ((st = http_head_get("Location", g->head, g->headsz)) == + NULL) { + warnx("redirect without location header"); + return -1; + } + + dodbg("Location: %s", st->val); + host = url2host(st->val, &port, &path); + http_get_free(g); + if (host == NULL) + return -1; + goto again; + } + code = g->code; /* Copy the body part into our buffer. */ -- I'm not entirely sure you are real.