Skip to content

Commit 02089e2

Browse files
Add request_body_size_within_limit method.
1 parent d7ee6d7 commit 02089e2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tabpy/tabpy_server/handlers/base_handler.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def initialize(self, app):
127127
self.username = None
128128
self.password = None
129129
self.eval_timeout = self.settings[SettingsParameters.EvaluateTimeout]
130+
self.max_request_size = app.max_request_size
130131

131132
self.logger = ContextLoggerWrapper(self.request)
132133
self.logger.enable_context_logging(
@@ -442,3 +443,27 @@ def fail_with_auth_error(self):
442443
info="Not Acceptable",
443444
log_message="Username or password provided when authentication not available.",
444445
)
446+
447+
def request_body_size_within_limit(self):
448+
"""
449+
Determines if the request body size is within the specified limit.
450+
451+
Returns
452+
-------
453+
bool
454+
True if the request body size is within the limit, False otherwise.
455+
"""
456+
headers = self.request.headers
457+
458+
if "Content-Length" in headers:
459+
content_length = int(headers["Content-Length"])
460+
461+
if content_length > self.max_request_size:
462+
self.error_out(
463+
413,
464+
info="Request Entity Too Large",
465+
log_message="Request body size exceeds the specified limit.",
466+
)
467+
return False
468+
469+
return True

0 commit comments

Comments
 (0)