#include <string.h>
#include <sys/socket.h>
#include <pwd.h>
+#include <sys/signal.h>
#include <errno.h>
#ifdef HAVE_CONFIG_H
if((resp = parseresp(out)) == NULL)
break;
replstr(&resp->ver, req->ver);
+
+ if(!getheader(resp, "server"))
+ headappheader(resp, "Server", sprintf3("ashd/%s", VERSION));
if(!strcmp(req->ver, "HTTP/1.0")) {
writeresp(in, resp);
fprintf(in, "\r\n");
- if((hd = getheader(resp, "content-length")) != NULL) {
- dlen = passdata(out, in, -1);
- if(dlen != atoo(hd))
+ if(!strcasecmp(req->method, "head")) {
+ if(!hasheader(req, "connection", "keep-alive"))
+ break;
+ } else if((hd = getheader(resp, "content-length")) != NULL) {
+ dlen = atoo(hd);
+ if(passdata(out, in, dlen) != dlen)
break;
if(!hasheader(req, "connection", "keep-alive"))
break;
if(hasheader(req, "connection", "close") || hasheader(resp, "connection", "close"))
break;
} else if(!strcmp(req->ver, "HTTP/1.1")) {
- if((hd = getheader(resp, "content-length")) != NULL) {
+ if(!strcasecmp(req->method, "head")) {
writeresp(in, resp);
fprintf(in, "\r\n");
- dlen = passdata(out, in, -1);
- if(dlen != atoo(hd))
+ } else if((hd = getheader(resp, "content-length")) != NULL) {
+ writeresp(in, resp);
+ fprintf(in, "\r\n");
+ dlen = atoo(hd);
+ if(passdata(out, in, dlen) != dlen)
break;
} else if(!getheader(resp, "transfer-encoding")) {
headappheader(resp, "Transfer-Encoding", "chunked");
usage(stderr);
exit(1);
}
- if((plex = stdmkchild(argv + ++i)) < 0) {
+ if((plex = stdmkchild(argv + ++i, NULL, NULL)) < 0) {
flog(LOG_ERR, "could not spawn root multiplexer: %s", strerror(errno));
return(1);
}
exit(1);
}
}
+ signal(SIGPIPE, SIG_IGN);
if(daemonize) {
daemon(0, 0);
}
- if(pidout != NULL)
+ if(pidout != NULL) {
fprintf(pidout, "%i\n", getpid());
- fclose(pidout);
+ fclose(pidout);
+ }
ioloop();
return(0);
}