summaryrefslogtreecommitdiffstats
path: root/custodia/httpd/server.py
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-06-05 10:56:29 -0400
committerSimo Sorce <simo@redhat.com>2015-06-05 10:56:29 -0400
commiteff99ee7a065e6e122dbd7cee136a2651073d224 (patch)
tree40761c5cc8ac6ff0cc270b4eb0faa3e62beda368 /custodia/httpd/server.py
parentf68ec64138d5b259788f25b54deec12e80a95ec7 (diff)
downloadcustodia-eff99ee7a065e6e122dbd7cee136a2651073d224.tar.gz
custodia-eff99ee7a065e6e122dbd7cee136a2651073d224.tar.xz
custodia-eff99ee7a065e6e122dbd7cee136a2651073d224.zip
Add basic debugging capabilities
If debug is set to True, then custodia's own Exception handlers will print a stack trace to standard output to aid debugging. Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'custodia/httpd/server.py')
-rw-r--r--custodia/httpd/server.py17
1 files changed, 5 insertions, 12 deletions
diff --git a/custodia/httpd/server.py b/custodia/httpd/server.py
index dc88aef..240e3b6 100644
--- a/custodia/httpd/server.py
+++ b/custodia/httpd/server.py
@@ -10,14 +10,13 @@ except ImportError:
from http.server import BaseHTTPRequestHandler
from socketserver import ForkingMixIn, UnixStreamServer
from urllib.parse import urlparse, parse_qs
-import io
+from custodia.log import stacktrace
+from custodia.log import debug as log_debug
import os
import shutil
import six
import socket
import struct
-import sys
-import traceback
SO_PEERCRED = 17
MAX_REQUEST_SIZE = 10*1024*1024 # For now limit body to 10MiB
@@ -28,15 +27,9 @@ class HTTPError(Exception):
def __init__(self, code=None, message=None):
self.code = code if code is not None else 500
self.mesg = message
- super(HTTPError, self).__init__('%d: %s' % (self.code, self.mesg))
-
-
-def stacktrace():
- with io.BytesIO() as f:
- _, _, tb = sys.exc_info()
- traceback.print_tb(tb, None, file=f)
- del tb
- return f.getvalue()
+ errstring = '%d: %s' % (self.code, self.mesg)
+ log_debug(errstring)
+ super(HTTPError, self).__init__(errstring)
class ForkingLocalHTTPServer(ForkingMixIn, UnixStreamServer):