7 hredirected(HConnect *c, char *how, char *uri)
10 char *s, *ss, *scheme, *host;
11 char sayport[NETPATHLEN];
14 scheme = c->scheme? c->scheme: "http";
16 if(strchr(uri, ':') != nil)
18 else if(uri[0] != '/'){
19 s = strrchr(c->req.uri, '/');
22 ss = halloc(c, strlen(c->req.uri) + strlen(uri) + 2 + UTFmax);
23 sprint(ss, "%s/%s", c->req.uri, uri);
29 if((strcmp(scheme, "http") == 0 && atoi(c->port) == 80) ||
30 (strcmp(scheme, "https") == 0 && atoi(c->port) == 443) ||
31 strchr(host, ':') != nil)
34 snprint(sayport, sizeof sayport, ":%s", c->port);
36 n = snprint(c->xferbuf, HBufSize,
37 "<head><title>Redirection</title></head>\r\n"
38 "<body><h1>Redirection</h1>\r\n"
39 "Your selection can be found <a href=\"%U\"> here</a>.<p></body>\r\n", uri);
42 hprint(hout, "%s %s\r\n", hversion, how);
43 hprint(hout, "Date: %D\r\n", time(nil));
44 hprint(hout, "Server: Plan9\r\n");
45 hprint(hout, "Content-type: text/html\r\n");
46 hprint(hout, "Content-Length: %d\r\n", n);
47 if(host == nil || host[0] == 0)
48 hprint(hout, "Location: %U\r\n", uri);
50 hprint(hout, "Location: %s://%U%s%U\r\n",
51 scheme, host, sayport, uri);
53 hprint(hout, "Connection: close\r\n");
55 hprint(hout, "Connection: Keep-Alive\r\n");
58 if(strcmp(c->req.meth, "HEAD") != 0)
59 hwrite(hout, c->xferbuf, n);
62 if(host == nil || host[0] == 0)
63 c->replog(c, "Reply: %s\nRedirect: %U\n", how, uri);
65 c->replog(c, "Reply: %s\nRedirect: %s://%U%s%U\n",
66 how, scheme, host, sayport, uri);
71 hmoved(HConnect *c, char *uri)
73 return hredirected(c, "301 Moved Permanently", uri);