summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramitt0012016-10-27 10:50:42 +0530
committerBarry Warsaw2016-10-30 18:11:34 -0400
commit94d0949ac6565f329b79fc54e9f56d335cdc647a (patch)
tree89efadf87acb6af21518f4b8f49a8e08d5c742d9
parentd2418de626e51f76cf33c6d93b80e7968c356c97 (diff)
downloadmailman-94d0949ac6565f329b79fc54e9f56d335cdc647a.tar.gz
mailman-94d0949ac6565f329b79fc54e9f56d335cdc647a.tar.zst
mailman-94d0949ac6565f329b79fc54e9f56d335cdc647a.zip
-rw-r--r--src/mailman/rest/wsgiapp.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/mailman/rest/wsgiapp.py b/src/mailman/rest/wsgiapp.py
index f3290416e..4e05069b4 100644
--- a/src/mailman/rest/wsgiapp.py
+++ b/src/mailman/rest/wsgiapp.py
@@ -18,6 +18,7 @@
"""Basic WSGI Application object for REST server."""
import re
+import time
import logging
from base64 import b64decode
@@ -63,7 +64,8 @@ class StderrLogger:
class AdminWebServiceWSGIRequestHandler(WSGIRequestHandler):
- """Handler class which just logs output to the right place."""
+ """Handler class which logs output to the right place and prepend headers
+ to the error response."""
def log_message(self, format, *args):
"""See `BaseHTTPRequestHandler`."""
@@ -74,6 +76,26 @@ class AdminWebServiceWSGIRequestHandler(WSGIRequestHandler):
# the log file.
return StderrLogger()
+ def send_error(self, code, message=None, explain=None):
+ """See `BaseHTTPRequestHandler`."""
+ err_code = "{0} {1}".format(code.value, code.name.replace('_', ' '))
+ header_dict = dict(
+ status="{0} {1}".format(self.request_version, err_code),
+ rsp_date=time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.gmtime()),
+ server="{0} {1}".format(self.server_version, self.sys_version),
+ content_type=self.error_content_type)
+ # Prepare headers and prepend it to the error response body
+ error_headers = ("""\
+%(status)s
+Date: %(rsp_date)s
+Server: %(server)s
+content-type: %(content_type)s\n
+""" % header_dict)
+ self.error_message_format = error_headers + self.error_message_format
+ # Let parent method handle rest of the logic
+ super().send_error(code, message, explain)
+
+
class Middleware:
"""Falcon middleware object for Mailman's REST API.