Skip to content

Commit

Permalink
Use tornado gzip support instead of doing it manually.
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Riggs committed Feb 8, 2022
1 parent 4d8d4ae commit 59eac3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
4 changes: 4 additions & 0 deletions tabpy/tabpy_server/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ def run(self):
logger.critical(msg)
raise RuntimeError(msg)

settings = {}
if self.settings[SettingsParameters.GzipEnabled] == True:
settings["decompress_request"] = True
application.listen(
self.settings[SettingsParameters.Port],
ssl_options=ssl_options,
max_buffer_size=max_request_size,
max_body_size=max_request_size,
**settings,
)

logger.info(
Expand Down
15 changes: 2 additions & 13 deletions tabpy/tabpy_server/handlers/evaluation_plane_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from tornado import gen
from datetime import timedelta
from tabpy.tabpy_server.handlers.util import AuthErrorStates
import gzip


class RestrictedTabPy:
Expand Down Expand Up @@ -65,13 +64,7 @@ def initialize(self, executor, app):
@gen.coroutine
def _post_impl(self):

self.logger.log(logging.DEBUG, f"PreProcessing POST request ...")
if self.settings[SettingsParameters.GzipEnabled] == True and 'Content-Encoding' in self.request.headers and 'gzip' in self.request.headers['Content-Encoding']:
self.logger.log(logging.DEBUG, f"Decoding Gzipped POST request ... '{self.request.body}'")
body = json.loads(gzip.decompress(self.request.body).decode("utf-8"))
self.logger.log(logging.DEBUG, f"Decoded Gzipped POST request ... '{body}'")
else:
body = json.loads(self.request.body)
body = json.loads(self.request.body.decode("utf-8"))
self.logger.log(logging.DEBUG, f"Processing POST request '{body}'...")
if "script" not in body:
self.error_out(400, "Script is empty.")
Expand Down Expand Up @@ -121,11 +114,7 @@ def _post_impl(self):
return

if result is not None:
if self.settings[SettingsParameters.GzipEnabled] == True and 'Content-Encoding' in self.request.headers and 'gzip' in self.request.headers['Content-Encoding']:
self.write(gzip.compress(simplejson.dumps(result, ignore_nan=True).encode('utf-8')))
self.set_header("Content-Encoding", "gzip")
else:
self.write(simplejson.dumps(result, ignore_nan=True).encode('utf-8'))
self.write(simplejson.dumps(result, ignore_nan=True))
else:
self.write("null")
self.finish()
Expand Down

0 comments on commit 59eac3e

Please sign in to comment.