diff options
Diffstat (limited to 'apifw/http.py')
-rw-r--r-- | apifw/http.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/apifw/http.py b/apifw/http.py index 7b5a8e9..7761874 100644 --- a/apifw/http.py +++ b/apifw/http.py @@ -14,6 +14,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. +import bottle + + HTTP_OK = 200 HTTP_CREATED = 201 HTTP_UNAUTHORIZED = 401 @@ -105,10 +108,13 @@ class HttpTransaction: self._counter() self._log_request() data = callback(*args, **kwargs) + self._logger({'data': type(data)}) self._log_callback() self.amend_response() self._log_response() return data + except StaticFile as e: + return bottle.static_file(e.filename, '/') except SystemExit: # If we're exiting, we exit. No need to log an error. raise @@ -118,11 +124,21 @@ class HttpTransaction: raise +class StaticFile(Exception): + + def __init__(self, filename): + super().__init__() + self.filename = filename + + def __getitem__(self, key): + return None + + class Response: def __init__(self, values): self._dict = {} - self._keys = ['status', 'headers', 'body'] + self._keys = ['status', 'headers', 'body', 'static-file'] for key in self._keys: self[key] = '' for key, value in values.items(): |