aboutsummaryrefslogtreecommitdiff
path: root/server_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'server_http.c')
-rw-r--r--server_http.c63
1 files changed, 26 insertions, 37 deletions
diff --git a/server_http.c b/server_http.c
index 1953036..3a5d84e 100644
--- a/server_http.c
+++ b/server_http.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server_http.c,v 1.54 2014/10/25 03:23:49 lteo Exp $ */
+/* $OpenBSD: server_http.c,v 1.58 2015/01/01 14:15:02 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -23,13 +23,11 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/tree.h>
-#include <sys/hash.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
-#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
@@ -665,10 +663,11 @@ 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 = "";
- char *httpmsg, *extraheader = NULL;
+ struct http_descriptor *desc = clt->clt_descreq;
+ const char *httperr = NULL, *style;
+ char *httpmsg, *body = NULL, *extraheader = NULL;
char tmbuf[32], hbuf[128];
- const char *style;
+ int bodylen;
if ((httperr = server_httperror_byid(code)) == NULL)
httperr = "Unknown Error";
@@ -696,8 +695,6 @@ server_abort_http(struct client *clt, u_int code, const char *msg)
}
break;
default:
-<<<<<<< server_http.c
-=======
/*
* Do not send details of the error. Traditionally,
* web servers responsed with the request path on 40x
@@ -705,7 +702,6 @@ server_abort_http(struct client *clt, u_int code, const char *msg)
* Instead of sanitizing the path here, we just don't
* reprint it.
*/
->>>>>>> 1.54
break;
}
@@ -713,17 +709,10 @@ server_abort_http(struct client *clt, u_int code, const char *msg)
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"
+
+ /* Generate simple HTML error document */
+ if ((bodylen = asprintf(&body,
+ "<!DOCTYPE html>\n"
"<html>\n"
"<head>\n"
"<title>%03d %s</title>\n"
@@ -731,14 +720,26 @@ server_abort_http(struct client *clt, u_int code, const char *msg)
"</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,
+ code, httperr, style, code, httperr, HTTPD_SERVERNAME)) == -1)
+ goto done;
+
+ /* Add basic HTTP headers */
+ 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"
+ "Content-Length: %d\r\n"
+ "%s"
+ "\r\n"
+ "%s",
+ code, httperr, tmbuf, HTTPD_SERVERNAME, bodylen,
extraheader == NULL ? "" : extraheader,
- code, httperr, style, code, httperr, text,
- HTTPD_SERVERNAME) == -1)
+ desc->http_method == HTTP_METHOD_HEAD ? "" : body) == -1)
goto done;
/* Dump the message without checking for success */
@@ -746,6 +747,7 @@ server_abort_http(struct client *clt, u_int code, const char *msg)
free(httpmsg);
done:
+ free(body);
free(extraheader);
if (asprintf(&httpmsg, "%s (%03d %s)", msg, code, httperr) == -1) {
server_close(clt, msg);
@@ -758,27 +760,14 @@ server_abort_http(struct client *clt, u_int code, const char *msg)
void
server_close_http(struct client *clt)
{
-<<<<<<< server_http.c
struct http_descriptor *desc;
desc = clt->clt_descreq;
server_httpdesc_free(desc);
free(desc);
clt->clt_descreq = NULL;
-=======
- struct http_descriptor *desc;
->>>>>>> 1.54
-
-<<<<<<< server_http.c
- desc = clt->clt_descresp;
-=======
- desc = clt->clt_descreq;
- server_httpdesc_free(desc);
- free(desc);
- clt->clt_descreq = NULL;
desc = clt->clt_descresp;
->>>>>>> 1.54
server_httpdesc_free(desc);
free(desc);
clt->clt_descresp = NULL;