From 915e923e3542da9fd11be5f1d46724fc10e7da3b Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <valenok@gmail.com>
Date: Thu, 10 Oct 2013 07:46:19 -0700
Subject: [PATCH] Firing MG_HTTP_ERROR

---
 build/src/mongoose.c | 12 +++++++-----
 mongoose.c           | 14 ++++++++------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/build/src/mongoose.c b/build/src/mongoose.c
index ffa0d521a..a961010ad 100644
--- a/build/src/mongoose.c
+++ b/build/src/mongoose.c
@@ -126,11 +126,13 @@ static void send_http_error(struct mg_connection *conn, int status,
   }
   DEBUG_TRACE(("[%s]", buf));
 
-  mg_printf(conn, "HTTP/1.1 %d %s\r\n"
-            "Content-Length: %d\r\n"
-            "Connection: %s\r\n\r\n", status, reason, len,
-            suggest_connection_header(conn));
-  conn->num_bytes_sent += mg_printf(conn, "%s", buf);
+  if (call_user(MG_HTTP_ERROR, conn, (void *) (long) status) == 0) {
+    mg_printf(conn, "HTTP/1.1 %d %s\r\n"
+              "Content-Length: %d\r\n"
+              "Connection: %s\r\n\r\n", status, reason, len,
+              suggest_connection_header(conn));
+    conn->num_bytes_sent += mg_printf(conn, "%s", buf);
+  }
 }
 
 // Write data to the IO channel - opened file descriptor, socket or SSL
diff --git a/mongoose.c b/mongoose.c
index 4f6d3f0df..2cb3bf4be 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -2293,11 +2293,13 @@ static void send_http_error(struct mg_connection *conn, int status,
   }
   DEBUG_TRACE(("[%s]", buf));
 
-  mg_printf(conn, "HTTP/1.1 %d %s\r\n"
-            "Content-Length: %d\r\n"
-            "Connection: %s\r\n\r\n", status, reason, len,
-            suggest_connection_header(conn));
-  conn->num_bytes_sent += mg_printf(conn, "%s", buf);
+  if (call_user(MG_HTTP_ERROR, conn, (void *) (long) status) == 0) {
+    mg_printf(conn, "HTTP/1.1 %d %s\r\n"
+              "Content-Length: %d\r\n"
+              "Connection: %s\r\n\r\n", status, reason, len,
+              suggest_connection_header(conn));
+    conn->num_bytes_sent += mg_printf(conn, "%s", buf);
+  }
 }
 
 // Write data to the IO channel - opened file descriptor, socket or SSL
@@ -5022,7 +5024,7 @@ static void process_new_connection(struct mg_connection *conn) {
 
     if (ebuf[0] == '\0') {
       handle_request(conn);
-      call_user(MG_REQUEST_END, conn, (void *) (long) conn->status_code);
+      call_user(MG_REQUEST_END, conn, (void *) conn->status_code);
       log_access(conn);
     }
     if (ri->remote_user != NULL) {
-- 
GitLab