wsgi: Serve '500 Internal Server Error' page when errors occur.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 24 Nov 2012 19:44:23 +0000 (20:44 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 5 Dec 2012 17:40:25 +0000 (18:40 +0100)
Autobuild-User(master): Jelmer Vernooij <jelmer@samba.org>
Autobuild-Date(master): Wed Dec  5 18:40:25 CET 2012 on sn-devel-104

source4/web_server/wsgi.c

index 615726ad7ac2ea730f707b09afc8a56d1d417727..17ad65afe41276781bd583573656688dd892d46e 100644 (file)
@@ -410,6 +410,22 @@ error:
        return NULL;
 }
 
+static void wsgi_serve_500(struct websrv_context *web)
+{
+       struct http_header *headers = NULL;
+       const char *contents[] = {
+               "An internal server error occurred while handling this request. ",
+               "Please refer to the server logs for more details. ",
+               NULL
+       };
+       int i;
+
+       websrv_output_headers(web, "500 Internal Server Error", headers);
+       for (i = 0; contents[i]; i++) {
+               websrv_output(web, contents[i], strlen(contents[i]));
+       }
+}
+
 static void wsgi_process_http_input(struct web_server_data *wdata,
                                    struct websrv_context *web)
 {
@@ -453,6 +469,7 @@ static void wsgi_process_http_input(struct web_server_data *wdata,
 
        if (py_environ == NULL) {
                DEBUG_Print_PyError(0, "Unable to create WSGI environment object");
+               wsgi_serve_500(web);
                return;
        }
 
@@ -461,6 +478,7 @@ static void wsgi_process_http_input(struct web_server_data *wdata,
 
        if (result == NULL) {
                DEBUG_Print_PyError(0, "error while handling request");
+               wsgi_serve_500(web);
                return;
        }
 
@@ -469,6 +487,7 @@ static void wsgi_process_http_input(struct web_server_data *wdata,
 
        if (iter == NULL) {
                DEBUG_Print_PyError(0, "application did not return iterable");
+               wsgi_serve_500(web);
                return;
        }