kopia lustrzana https://github.com/cirospaciari/socketify.py
feat: add support for max content length
rodzic
e3d47f8339
commit
5ca6ae06ec
|
@ -186,6 +186,7 @@ void uws_add_server_name(int ssl, uws_app_t *app, const char *hostname_pattern,
|
|||
void uws_add_server_name_with_options(int ssl, uws_app_t *app, const char *hostname_pattern, size_t hostname_pattern_length, struct us_socket_context_options_t options);
|
||||
void uws_missing_server_name(int ssl, uws_app_t *app, uws_missing_server_handler handler, void *user_data);
|
||||
void uws_filter(int ssl, uws_app_t *app, uws_filter_handler handler, void *user_data);
|
||||
void uws_set_max_content_length(uws_app_t *app, size_t maxContentLength);
|
||||
|
||||
void uws_res_close(int ssl, uws_res_t *res);
|
||||
void uws_res_end(int ssl, uws_res_t *res, const char *data, size_t length, bool close_connection);
|
||||
|
|
|
@ -1001,8 +1001,6 @@ def uws_generic_method_handler(res, req, user_data):
|
|||
response = AppResponse(res, app)
|
||||
request = AppRequest(req, app)
|
||||
|
||||
response._content_length = int(request.get_header("content-length"))
|
||||
|
||||
try:
|
||||
if inspect.iscoroutinefunction(handler):
|
||||
response.grab_aborted_handler()
|
||||
|
@ -1484,7 +1482,6 @@ class AppResponse:
|
|||
self._chunkFuture = None
|
||||
self._dataFuture = None
|
||||
self._data = None
|
||||
self._content_length = None
|
||||
|
||||
def cork(self, callback):
|
||||
self.app.loop.is_idle = False
|
||||
|
@ -2038,11 +2035,6 @@ class AppResponse:
|
|||
return self
|
||||
|
||||
def on_data(self, handler):
|
||||
if self.app.max_content_length is not None and self._content_length is not None:
|
||||
if self._content_length > self.app.max_content_length:
|
||||
self.write_status(413).end("413 Request Entity Too Large")
|
||||
return self
|
||||
|
||||
if not self.aborted:
|
||||
if hasattr(handler, "__call__"):
|
||||
self._data_handler = handler
|
||||
|
@ -2626,7 +2618,7 @@ class App:
|
|||
task_factory_max_items=100_000,
|
||||
lifespan=True,
|
||||
idle_relaxation_time=0.01,
|
||||
max_content_length=None,
|
||||
max_content_length=0,
|
||||
):
|
||||
|
||||
socket_options_ptr = ffi.new("struct us_socket_context_options_t *")
|
||||
|
@ -2634,7 +2626,6 @@ class App:
|
|||
self._options = options
|
||||
self._template = None
|
||||
self.lifespan = lifespan
|
||||
self.max_content_length = max_content_length
|
||||
# keep socket data alive for CFFI
|
||||
self._socket_refs = {}
|
||||
self._native_options = []
|
||||
|
@ -2698,7 +2689,6 @@ class App:
|
|||
socket_options.ssl_prefer_low_memory_usage = ffi.cast(
|
||||
"int", options.ssl_prefer_low_memory_usage
|
||||
)
|
||||
|
||||
else:
|
||||
self.is_ssl = False
|
||||
self.SSL = ffi.cast("int", 0)
|
||||
|
@ -2716,6 +2706,7 @@ class App:
|
|||
self._ptr = ffi.new_handle(self)
|
||||
if bool(lib.uws_constructor_failed(self.SSL, self.app)):
|
||||
raise RuntimeError("Failed to create connection")
|
||||
lib.uws_set_max_content_length(self.app, max_content_length)
|
||||
|
||||
self.handlers = []
|
||||
self.error_handler = None
|
||||
|
|
Ładowanie…
Reference in New Issue