On Sun, Nov 23, 2014 at 08:15:47PM -0500, Bertrand Janin wrote:
> 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)
Nice catch. However, your diff will leak body if the second
asprintf(3) fails.
Since we are probably not supposed to send a "Content-Type" header I
think it makes sense to duplicate the httpmsg generating code in this
case; it feels easier.
While in there nuke unneeded text variable and shuffle variable
declarations around.
OK?
diff --git server_http.c server_http.c
index 05e3381..bc77fc4 100644
--- server_http.c
+++ server_http.c
@@ -665,10 +665,10 @@ server_abort_http(struct client *clt, u_int code, const
char *msg)
struct server *srv = clt->clt_srv;
struct server_config *srv_conf = &srv->srv_conf;
struct bufferevent *bev = clt->clt_bev;
- const char *httperr = NULL, *text = "";
+ struct http_descriptor *desc = clt->clt_descreq;
+ const char *httperr, *style;
char *httpmsg, *extraheader = NULL;
char tmbuf[32], hbuf[128];
- const char *style;
if ((httperr = server_httperror_byid(code)) == NULL)
httperr = "Unknown Error";
@@ -706,37 +706,48 @@ server_abort_http(struct client *clt, u_int code, const
char *msg)
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 simple HTTP+HTML error document */
- if (asprintf(&httpmsg,
- "HTTP/1.0 %03d %s\r\n"
- "Date: %s\r\n"
- "Server: %s\r\n"
- "Connection: close\r\n"
- "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",
- code, httperr, tmbuf, HTTPD_SERVERNAME,
- extraheader == NULL ? "" : extraheader,
- code, httperr, style, code, httperr, text,
- HTTPD_SERVERNAME) == -1)
- goto done;
+ if (desc->http_method == HTTP_METHOD_HEAD) {
+ /* Generate HTTP header */
+ if (asprintf(&httpmsg,
+ "HTTP/1.0 %03d %s\r\n"
+ "Date: %s\r\n"
+ "Server: %s\r\n"
+ "Connection: close\r\n"
+ "%s\r\n", code, httperr, tmbuf, HTTPD_SERVERNAME,
+ extraheader == NULL ? "" : extraheader) == -1)
+ goto done;
+ } else {
+ /* 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 simple HTTP+HTML error document */
+ if (asprintf(&httpmsg,
+ "HTTP/1.0 %03d %s\r\n"
+ "Date: %s\r\n"
+ "Server: %s\r\n"
+ "Connection: close\r\n"
+ "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"
+ "<hr>\n<address>%s</address>\n"
+ "</body>\n"
+ "</html>\n",
+ code, httperr, tmbuf, HTTPD_SERVERNAME,
+ extraheader == NULL ? "" : extraheader, code, httperr,
+ style, code, httperr, HTTPD_SERVERNAME) == -1)
+ goto done;
+ }
/* Dump the message without checking for success */
server_dump(clt, httpmsg, strlen(httpmsg));
--
I'm not entirely sure you are real.