Hi,

This patch updates server_abort_http() to only send the body of default http
error if the method is not HEAD. I first noticed that with curl -v -I which
complains about the excess data:

    * Excess found in a non pipelined read: excess = 397 url = /asd 
(zero-length body)


Index: usr.sbin/httpd/server_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.54
diff -u -p -r1.54 server_http.c
--- usr.sbin/httpd/server_http.c        25 Oct 2014 03:23:49 -0000      1.54
+++ usr.sbin/httpd/server_http.c        23 Nov 2014 23:49:44 -0000
@@ -665,8 +665,9 @@ server_abort_http(struct client *clt, u_
        struct server           *srv = clt->clt_srv;
        struct server_config    *srv_conf = &srv->srv_conf;
        struct bufferevent      *bev = clt->clt_bev;
+       struct http_descriptor  *desc = clt->clt_descreq;
        const char              *httperr = NULL, *text = "";
-       char                    *httpmsg, *extraheader = NULL;
+       char                    *httpmsg, *body = NULL, *extraheader = NULL;
        char                     tmbuf[32], hbuf[128];
        const char              *style;
 
@@ -706,10 +707,33 @@ server_abort_http(struct client *clt, u_
                break;
        }
 
-       /* A CSS stylesheet allows minimal customization by the user */
-       style = "body { background-color: white; color: black; font-family: "
-           "'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }\n"
-           "hr { border: 0; border-bottom: 1px dashed; }\n";
+       /* Generate the body (not needed for HEAD requests) */
+       if (desc->http_method != HTTP_METHOD_HEAD) {
+               /* A CSS stylesheet allows minimal customization by the user */
+               style = "body { background-color: white; color: black; "
+                       "font-family: 'Comic Sans MS', 'Chalkboard SE', "
+                       "'Comic Neue', sans-serif; }\n"
+                       "hr { border: 0; border-bottom: 1px dashed; }\n";
+
+               if (asprintf(&body,
+                   "<!DOCTYPE HTML PUBLIC "
+                   "\"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
+                   "<html>\n"
+                   "<head>\n"
+                   "<title>%03d %s</title>\n"
+                   "<style type=\"text/css\"><!--\n%s\n--></style>\n"
+                   "</head>\n"
+                   "<body>\n"
+                   "<h1>%03d %s</h1>\n"
+                   "<div id='m'>%s</div>\n"
+                   "<hr>\n<address>%s</address>\n"
+                   "</body>\n"
+                   "</html>\n",
+                   code, httperr, style, code, httperr, text,
+                   HTTPD_SERVERNAME) == -1)
+                       goto done;
+       }
+
        /* Generate simple HTTP+HTML error document */
        if (asprintf(&httpmsg,
            "HTTP/1.0 %03d %s\r\n"
@@ -719,28 +743,16 @@ server_abort_http(struct client *clt, u_
            "Content-Type: text/html\r\n"
            "%s"
            "\r\n"
-           "<!DOCTYPE HTML PUBLIC "
-           "\"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
-           "<html>\n"
-           "<head>\n"
-           "<title>%03d %s</title>\n"
-           "<style type=\"text/css\"><!--\n%s\n--></style>\n"
-           "</head>\n"
-           "<body>\n"
-           "<h1>%03d %s</h1>\n"
-           "<div id='m'>%s</div>\n"
-           "<hr>\n<address>%s</address>\n"
-           "</body>\n"
-           "</html>\n",
+           "%s",
            code, httperr, tmbuf, HTTPD_SERVERNAME,
            extraheader == NULL ? "" : extraheader,
-           code, httperr, style, code, httperr, text,
-           HTTPD_SERVERNAME) == -1)
+           body == NULL ? "" : body) == -1)
                goto done;
 
        /* Dump the message without checking for success */
        server_dump(clt, httpmsg, strlen(httpmsg));
        free(httpmsg);
+       free(body);
 
  done:
        free(extraheader);

Reply via email to