+ }
+ old = inbuf.b[headoff];
+ inbuf.b[headoff] = 0;
+ if((req = parserawreq(inbuf.b)) == NULL)
+ goto out;
+ inbuf.b[headoff] = old;
+ bufeat(inbuf, headoff);
+ /* We strip off the leading slash from the rest string, so
+ * that multiplexers can parse coherently. */
+ if(req->rest[0] == '/')
+ replrest(req, req->rest + 1);
+
+ /*
+ * Add metainformation and then send the request to the root
+ * multiplexer:
+ */
+ if(name.ss_family == AF_INET) {
+ headappheader(req, "X-Ash-Address", inet_ntop(AF_INET, &((struct sockaddr_in *)&name)->sin_addr, nmbuf, sizeof(nmbuf)));
+ headappheader(req, "X-Ash-Port", sprintf3("%i", ntohs(((struct sockaddr_in *)&name)->sin_port)));
+ } else if(name.ss_family == AF_INET6) {
+ headappheader(req, "X-Ash-Address", inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&name)->sin6_addr, nmbuf, sizeof(nmbuf)));
+ headappheader(req, "X-Ash-Port", sprintf3("%i", ntohs(((struct sockaddr_in6 *)&name)->sin6_port)));
+ }
+ cfd = sendreq(plex, req);
+
+ /*
+ * If there is message data, pass it:
+ */
+ if((hd = getheader(req, "content-length")) != NULL) {
+ dlen = atoo(hd);
+ if(dlen > 0)
+ passdata(fd, cfd, &inbuf, dlen);
+ }
+ /* Make sure to send EOF */
+ shutdown(cfd, SHUT_WR);
+
+ /*
+ * Find and decode the response header:
+ */
+ outbuf.d = 0;
+ headoff = readhead(cfd, &outbuf);
+ hd = memcpy(smalloc(headoff + 1), outbuf.b, headoff);
+ hd[headoff] = 0;
+ if((resp = parserawresp(hd)) == NULL)
+ goto out;
+
+ /*
+ * Pass the actual output:
+ */
+ sizebuf(outbuf, 65536);
+ sent = passdata(cfd, fd, &outbuf, -1);
+ sent -= headoff;
+
+ /*
+ * Check for connection expiry
+ */
+ if(strcasecmp(req->method, "head")) {
+ if((hd = getheader(resp, "content-length")) != NULL) {
+ if(sent != atoo(hd)) {
+ /* Exit because of error */
+ goto out;
+ }
+ } else {
+ if(((hd = getheader(resp, "transfer-encoding")) == NULL) || !strcasecmp(hd, "identity"))
+ break;
+ }
+ if(((hd = getheader(req, "connection")) != NULL) && !strcasecmp(hd, "close"))
+ break;
+ if(((hd = getheader(resp, "connection")) != NULL) && !strcasecmp(hd, "close"))
+ break;
+ }
+
+ close(cfd);
+ cfd = -1;
+ freehthead(req);
+ req = NULL;
+ freehthead(resp);
+ resp = NULL;