%1$i %2$s
\n" - "%3$s
\n" - "%4$s
\n" + "%3$s" " \n" "diff --git a/src/client.c b/src/client.c index 1332ab6..6519ad4 100644 --- a/src/client.c +++ b/src/client.c @@ -40,6 +40,7 @@ int client_request_handler(sock *client, int req_num) { int ret, client_keep_alive; char buf[64]; char msg_buf[4096]; + char msg_pre_buf[4096]; char err_msg[256]; err_msg[0] = 0; char *host, *hdr_connection, *webroot; @@ -107,9 +108,10 @@ int client_request_handler(sock *client, int req_num) { int len = 0; if (res.status->code >= 300 && res.status->code < 600) { http_error_msg *http_msg = http_get_error_msg(res.status->code); - len = sprintf(msg_buf, http_error_document, res.status->code, res.status->msg, - http_msg != NULL ? http_msg->err_msg : "", err_msg[0] != 0 ? err_msg : "", - res.status->code >= 300 && res.status->code < 400 ? "info" : "error"); + sprintf(msg_pre_buf, http_error_document, res.status->code, res.status->msg, + http_msg != NULL ? http_msg->err_msg : "", err_msg[0] != 0 ? err_msg : ""); + len = sprintf(msg_buf, http_default_document, res.status->code, res.status->msg, + msg_pre_buf, res.status->code >= 300 && res.status->code < 400 ? "info" : "error"); sprintf(buf, "%i", len); http_add_header_field(&res.hdr, "Content-Length", buf); http_add_header_field(&res.hdr, "Content-Type", "text/html; charset=UTF-8"); diff --git a/src/http.h b/src/http.h index 7031933..d03f8e6 100644 --- a/src/http.h +++ b/src/http.h @@ -111,7 +111,7 @@ http_error_msg http_error_messages[] = { {505, "The server does not support, or refuses to support, the HTTP protocol version that was used in the request message."} }; -const char *http_error_document = +const char *http_default_document = "\n" "\n" "
\n" @@ -119,53 +119,28 @@ const char *http_error_document = " \n" " \n" " \n" "\n" "\n" "%3$s
\n" - "%4$s
\n" + "%3$s" " \n" "%3$s
\n" + "%4$s
\n"; + void http_to_camel_case(char *str);