X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fhtparser.c;h=d1b0a1ce78f2445847e234bfe2b66eaec9572aab;hb=5226f7c50ec6ef6a2da9ca8e04d1afca2725e259;hp=503df99a719ffda1c859d19c0d929dd0745f88dc;hpb=6a7a868e28e79f5502cc4b37578c263f640439c8;p=ashd.git diff --git a/src/htparser.c b/src/htparser.c index 503df99..d1b0a1c 100644 --- a/src/htparser.c +++ b/src/htparser.c @@ -272,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; @@ -289,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"); + } else if((hd = getheader(resp, "content-length")) != NULL) { writeresp(in, resp); fprintf(in, "\r\n"); - dlen = passdata(out, in, -1); - if(dlen != atoo(hd)) + dlen = atoo(hd); + if(passdata(out, in, dlen) != dlen) break; } else if(!getheader(resp, "transfer-encoding")) { headappheader(resp, "Transfer-Encoding", "chunked");