+static int canonreq(struct hthead *req)
+{
+ char *p, *p2, *r;
+ int n;
+
+ if(req->url[0] == '/') {
+ replrest(req, req->url + 1);
+ if((p = strchr(req->rest, '?')) != NULL)
+ *p = 0;
+ return(1);
+ }
+ if((p = strstr(req->url, "://")) != NULL) {
+ n = p - req->url;
+ if(((n == 4) && !strncasecmp(req->url, "http", 4)) ||
+ ((n == 5) && !strncasecmp(req->url, "https", 5))) {
+ if(getheader(req, "host"))
+ return(0);
+ p += 3;
+ if((p2 = strchr(p, '/')) == NULL) {
+ headappheader(req, "Host", p);
+ free(req->url);
+ req->url = sstrdup("/");
+ } else {
+ r = sstrdup(p2);
+ *(p2++) = 0;
+ headappheader(req, "Host", p);
+ free(req->url);
+ req->url = r;
+ }
+ replrest(req, req->url + 1);
+ if((p = strchr(req->rest, '?')) != NULL)
+ *p = 0;
+ return(1);
+ }
+ }
+ return(0);
+}
+
+static int http10keep(struct hthead *req, struct hthead *resp)
+{
+ int fc;
+
+ fc = hasheader(resp, "connection", "close");
+ headrmheader(resp, "connection");
+ if(!fc && hasheader(req, "connection", "keep-alive")) {
+ headappheader(resp, "Connection", "Keep-Alive");
+ return(1);
+ } else {
+ return(0);
+ }
+}
+