mirror of
https://github.com/lammertb/libhttp.git
synced 2025-12-22 04:02:04 +03:00
Add content type and charset to the default error page
This commit is contained in:
@@ -2830,7 +2830,7 @@ send_http_error(struct mg_connection *conn, int status, const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
char buf[MG_BUF_LEN];
|
char buf[MG_BUF_LEN];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int len, i, page_handler_found, scope, truncated;
|
int len, i, page_handler_found, scope, truncated, has_body;
|
||||||
char date[64];
|
char date[64];
|
||||||
time_t curtime = time(NULL);
|
time_t curtime = time(NULL);
|
||||||
const char *error_handler = NULL;
|
const char *error_handler = NULL;
|
||||||
@@ -2917,17 +2917,24 @@ send_http_error(struct mg_connection *conn, int status, const char *fmt, ...)
|
|||||||
/* No custom error page. Send default error page. */
|
/* No custom error page. Send default error page. */
|
||||||
gmt_time_string(date, sizeof(date), &curtime);
|
gmt_time_string(date, sizeof(date), &curtime);
|
||||||
|
|
||||||
|
/* Errors 1xx, 204 and 304 MUST NOT send a body */
|
||||||
|
has_body = (status > 199 && status != 204 && status != 304);
|
||||||
|
|
||||||
conn->must_close = 1;
|
conn->must_close = 1;
|
||||||
mg_printf(conn, "HTTP/1.1 %d %s\r\n", status, status_text);
|
mg_printf(conn, "HTTP/1.1 %d %s\r\n", status, status_text);
|
||||||
send_no_cache_header(conn);
|
send_no_cache_header(conn);
|
||||||
|
if (has_body) {
|
||||||
|
mg_printf(conn,
|
||||||
|
"%s",
|
||||||
|
"Content-Type: text/plain; charset=utf-8\r\n");
|
||||||
|
}
|
||||||
mg_printf(conn,
|
mg_printf(conn,
|
||||||
"Date: %s\r\n"
|
"Date: %s\r\n"
|
||||||
"Connection: close\r\n\r\n",
|
"Connection: close\r\n\r\n",
|
||||||
date);
|
date);
|
||||||
|
|
||||||
/* Errors 1xx, 204 and 304 MUST NOT send a body */
|
/* Errors 1xx, 204 and 304 MUST NOT send a body */
|
||||||
if (status > 199 && status != 204 && status != 304) {
|
if (has_body) {
|
||||||
|
|
||||||
mg_printf(conn, "Error %d: %s\n", status, status_text);
|
mg_printf(conn, "Error %d: %s\n", status, status_text);
|
||||||
|
|
||||||
if (fmt != NULL) {
|
if (fmt != NULL) {
|
||||||
@@ -11389,7 +11396,8 @@ ssl_get_client_cert_info(struct mg_connection *conn)
|
|||||||
/* Calculate SHA1 fingerprint and store as a hex string */
|
/* Calculate SHA1 fingerprint and store as a hex string */
|
||||||
ulen = 0;
|
ulen = 0;
|
||||||
ASN1_digest((int (*)())i2d_X509, digest, (char *)cert, buf, &ulen);
|
ASN1_digest((int (*)())i2d_X509, digest, (char *)cert, buf, &ulen);
|
||||||
if (!hexdump2string(buf, (int)ulen, str_finger, (int)sizeof(str_finger))) {
|
if (!hexdump2string(
|
||||||
|
buf, (int)ulen, str_finger, (int)sizeof(str_finger))) {
|
||||||
*str_finger = 0;
|
*str_finger = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user