X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fhtparser.c;h=d1b0a1ce78f2445847e234bfe2b66eaec9572aab;hb=5226f7c50ec6ef6a2da9ca8e04d1afca2725e259;hp=17ad93abc7234142a3e11e54a5bab85fd3dc93ad;hpb=43c58ba25e47635c8f44e6b1cbda9247219a16b5;p=ashd.git diff --git a/src/htparser.c b/src/htparser.c index 17ad93a..d1b0a1c 100644 --- a/src/htparser.c +++ b/src/htparser.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #ifdef HAVE_CONFIG_H @@ -271,13 +272,19 @@ void serve(FILE *in, struct conn *conn) 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; @@ -288,11 +295,14 @@ void serve(FILE *in, struct conn *conn) 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"); @@ -453,7 +463,7 @@ int main(int argc, char **argv) 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); } @@ -483,12 +493,14 @@ int main(int argc, char **argv) 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); }