Skip to content

Commit 59eac3e

Browse files
author
Logan Riggs
committed
Use tornado gzip support instead of doing it manually.
1 parent 4d8d4ae commit 59eac3e

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

tabpy/tabpy_server/app/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ def run(self):
9696
logger.critical(msg)
9797
raise RuntimeError(msg)
9898

99+
settings = {}
100+
if self.settings[SettingsParameters.GzipEnabled] == True:
101+
settings["decompress_request"] = True
99102
application.listen(
100103
self.settings[SettingsParameters.Port],
101104
ssl_options=ssl_options,
102105
max_buffer_size=max_request_size,
103106
max_body_size=max_request_size,
107+
**settings,
104108
)
105109

106110
logger.info(

tabpy/tabpy_server/handlers/evaluation_plane_handler.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from tornado import gen
99
from datetime import timedelta
1010
from tabpy.tabpy_server.handlers.util import AuthErrorStates
11-
import gzip
1211

1312

1413
class RestrictedTabPy:
@@ -65,13 +64,7 @@ def initialize(self, executor, app):
6564
@gen.coroutine
6665
def _post_impl(self):
6766

68-
self.logger.log(logging.DEBUG, f"PreProcessing POST request ...")
69-
if self.settings[SettingsParameters.GzipEnabled] == True and 'Content-Encoding' in self.request.headers and 'gzip' in self.request.headers['Content-Encoding']:
70-
self.logger.log(logging.DEBUG, f"Decoding Gzipped POST request ... '{self.request.body}'")
71-
body = json.loads(gzip.decompress(self.request.body).decode("utf-8"))
72-
self.logger.log(logging.DEBUG, f"Decoded Gzipped POST request ... '{body}'")
73-
else:
74-
body = json.loads(self.request.body)
67+
body = json.loads(self.request.body.decode("utf-8"))
7568
self.logger.log(logging.DEBUG, f"Processing POST request '{body}'...")
7669
if "script" not in body:
7770
self.error_out(400, "Script is empty.")
@@ -121,11 +114,7 @@ def _post_impl(self):
121114
return
122115

123116
if result is not None:
124-
if self.settings[SettingsParameters.GzipEnabled] == True and 'Content-Encoding' in self.request.headers and 'gzip' in self.request.headers['Content-Encoding']:
125-
self.write(gzip.compress(simplejson.dumps(result, ignore_nan=True).encode('utf-8')))
126-
self.set_header("Content-Encoding", "gzip")
127-
else:
128-
self.write(simplejson.dumps(result, ignore_nan=True).encode('utf-8'))
117+
self.write(simplejson.dumps(result, ignore_nan=True))
129118
else:
130119
self.write("null")
131120
self.finish()

0 commit comments

Comments
 (0)