|
@@ -7,13 +7,15 @@ int
|
|
|
hredirected(HConnect *c, char *how, char *uri)
|
|
|
{
|
|
|
Hio *hout;
|
|
|
- char *s, *ss, *host;
|
|
|
+ char *s, *ss, *scheme, *host;
|
|
|
+ char sayport[NETPATHLEN];
|
|
|
int n;
|
|
|
|
|
|
+ scheme = c->scheme? c->scheme: "http";
|
|
|
host = c->head.host;
|
|
|
- if(strchr(uri, ':')){
|
|
|
+ if(strchr(uri, ':') != nil)
|
|
|
host = "";
|
|
|
- }else if(uri[0] != '/'){
|
|
|
+ else if(uri[0] != '/'){
|
|
|
s = strrchr(c->req.uri, '/');
|
|
|
if(s != nil)
|
|
|
*s = '\0';
|
|
@@ -24,6 +26,13 @@ hredirected(HConnect *c, char *how, char *uri)
|
|
|
*s = '/';
|
|
|
}
|
|
|
|
|
|
+ if((strcmp(scheme, "http") == 0 && atoi(c->port) == 80) ||
|
|
|
+ (strcmp(scheme, "https") == 0 && atoi(c->port) == 443) ||
|
|
|
+ strchr(host, ':') != nil)
|
|
|
+ sayport[0] = '\0';
|
|
|
+ else
|
|
|
+ snprint(sayport, sizeof sayport, ":%s", c->port);
|
|
|
+
|
|
|
n = snprint(c->xferbuf, HBufSize,
|
|
|
"<head><title>Redirection</title></head>\r\n"
|
|
|
"<body><h1>Redirection</h1>\r\n"
|
|
@@ -38,7 +47,8 @@ hredirected(HConnect *c, char *how, char *uri)
|
|
|
if(host == nil || host[0] == 0)
|
|
|
hprint(hout, "Location: %U\r\n", uri);
|
|
|
else
|
|
|
- hprint(hout, "Location: http://%U%U\r\n", host, uri);
|
|
|
+ hprint(hout, "Location: %s://%U%s%U\r\n",
|
|
|
+ scheme, host, sayport, uri);
|
|
|
if(c->head.closeit)
|
|
|
hprint(hout, "Connection: close\r\n");
|
|
|
else if(!http11(c))
|
|
@@ -48,12 +58,12 @@ hredirected(HConnect *c, char *how, char *uri)
|
|
|
if(strcmp(c->req.meth, "HEAD") != 0)
|
|
|
hwrite(hout, c->xferbuf, n);
|
|
|
|
|
|
- if(c->replog){
|
|
|
+ if(c->replog)
|
|
|
if(host == nil || host[0] == 0)
|
|
|
c->replog(c, "Reply: %s\nRedirect: %U\n", how, uri);
|
|
|
else
|
|
|
- c->replog(c, "Reply: %s\nRedirect: http://%U%U\n", how, host, uri);
|
|
|
- }
|
|
|
+ c->replog(c, "Reply: %s\nRedirect: %s://%U%s%U\n",
|
|
|
+ how, scheme, host, sayport, uri);
|
|
|
return hflush(hout);
|
|
|
}
|
|
|
|