htparser: Handle HEAD requests properly.
authorFredrik Tolf <fredrik@dolda2000.com>
Mon, 4 Oct 2010 22:36:36 +0000 (00:36 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Mon, 4 Oct 2010 22:36:36 +0000 (00:36 +0200)
src/htparser.c

index 503df99..4325e97 100644 (file)
@@ -276,7 +276,10 @@ void serve(FILE *in, struct conn *conn)
        if(!strcmp(req->ver, "HTTP/1.0")) {
            writeresp(in, resp);
            fprintf(in, "\r\n");
-           if((hd = getheader(resp, "content-length")) != NULL) {
+           if(!strcasecmp(req->method, "head")) {
+               if(!hasheader(req, "connection", "keep-alive"))
+                   break;
+           } else if((hd = getheader(resp, "content-length")) != NULL) {
                dlen = passdata(out, in, -1);
                if(dlen != atoo(hd))
                    break;
@@ -289,7 +292,10 @@ 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);