summaryrefslogtreecommitdiff
path: root/apifw/http.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-03-24 15:48:12 +0200
committerLars Wirzenius <liw@liw.fi>2018-03-24 18:14:47 +0200
commitf299215889b6acf8aff86243d50d4a54bb528021 (patch)
tree138c1c06d5645238f4244e1e26f380091143f370 /apifw/http.py
parentcdcf71634ffc16a3cd09a2ee2641ddbaaba165ec (diff)
downloadapifw-f299215889b6acf8aff86243d50d4a54bb528021.tar.gz
Change: support up/download of large blobs
This is very ugly. But it solves the problem, and apifw will need to be re-designed to support this properly.
Diffstat (limited to 'apifw/http.py')
-rw-r--r--apifw/http.py18
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():