Skip to content

Commit

Permalink
Add request_body_size_within_limit method.
Browse files Browse the repository at this point in the history
jakeichikawasalesforce committed May 19, 2023
1 parent d7ee6d7 commit 02089e2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tabpy/tabpy_server/handlers/base_handler.py
Original file line number Diff line number Diff line change
@@ -127,6 +127,7 @@ def initialize(self, app):
self.username = None
self.password = None
self.eval_timeout = self.settings[SettingsParameters.EvaluateTimeout]
self.max_request_size = app.max_request_size

self.logger = ContextLoggerWrapper(self.request)
self.logger.enable_context_logging(
@@ -442,3 +443,27 @@ def fail_with_auth_error(self):
info="Not Acceptable",
log_message="Username or password provided when authentication not available.",
)

def request_body_size_within_limit(self):
"""
Determines if the request body size is within the specified limit.
Returns
-------
bool
True if the request body size is within the limit, False otherwise.
"""
headers = self.request.headers

if "Content-Length" in headers:
content_length = int(headers["Content-Length"])

if content_length > self.max_request_size:
self.error_out(
413,
info="Request Entity Too Large",
log_message="Request body size exceeds the specified limit.",
)
return False

return True

0 comments on commit 02089e2

Please sign in to comment.