From 0b89e460a15f64e0d885d9f074eee33b06977752 Mon Sep 17 00:00:00 2001 From: szeka9 Date: Sat, 19 Sep 2026 17:05:21 +0200 Subject: [PATCH 1/2] Support 3xx status codes Add common status codes for redirection, except ones relying on HTTP caching or not widely used. --- docs/application_development/response.md | 5 +++++ docs/setup.md | 1 + src/pyrobusta/protocol/http.py | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/docs/application_development/response.md b/docs/application_development/response.md index a9f0c6e..92b8198 100644 --- a/docs/application_development/response.md +++ b/docs/application_development/response.md @@ -56,6 +56,11 @@ The following list of status codes are supported by PyRobusta: | 200 | OK | | 201 | Created | | 204 | No Content | +| 301 | Moved Permanently | +| 302 | Found | +| 303 | See Other | +| 307 | Temporary Redirect | +| 308 | Permanent Redirect | | 400 | Bad Request | | 401 | Unauthorized | | 403 | Forbidden | diff --git a/docs/setup.md b/docs/setup.md index ba7e970..1fab1fa 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -61,6 +61,7 @@ The server will skip Wi-Fi connection if the credentials are missing, allowing t ```python # boot.py +import asyncio import machine from pyrobusta import application diff --git a/src/pyrobusta/protocol/http.py b/src/pyrobusta/protocol/http.py index 437a48e..3120292 100644 --- a/src/pyrobusta/protocol/http.py +++ b/src/pyrobusta/protocol/http.py @@ -55,6 +55,16 @@ class HttpEngine: b"201 Created", 204, b"204 No Content", + 301, + b"301 Moved Permanently", + 302, + b"302 Found", + 303, + b"303 See Other", + 307, + b"307 Temporary Redirect", + 308, + b"308 Permanent Redirect", 400, b"400 Bad Request", 401, From e736418c46e8099cb8a052a865e841f636338c80 Mon Sep 17 00:00:00 2001 From: szeka9 Date: Sat, 19 Sep 2026 17:50:55 +0200 Subject: [PATCH 2/2] Use proper iterator in iterate_fs iterate_fs() uses os.listdir() that returns a complete list of entries. Instead, use ilistdir() that returns an iterator, avoiding large temporary allocations. --- src/pyrobusta/utils/assets.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pyrobusta/utils/assets.py b/src/pyrobusta/utils/assets.py index 064d901..82390a0 100644 --- a/src/pyrobusta/utils/assets.py +++ b/src/pyrobusta/utils/assets.py @@ -2,7 +2,18 @@ Helper functions to install assets. """ -from os import mkdir, listdir, stat +from os import mkdir, stat + +try: + from os import ilistdir +except ImportError: + from os import listdir + + def ilistdir(path): + """Fallback definition of ilistdir""" + for name in listdir(path): + yield (name,) + from pyrobusta import WORKING_DIR @@ -37,7 +48,7 @@ def iterate_fs(root, iter_mode=FS_ITER_FILE, path_mode=FS_ITER_ABS): dirs = [root] while dirs: current_directory = dirs.pop(0) - for name in listdir(current_directory): + for name, *_ in ilistdir(current_directory): if current_directory == "/": current_path = "/" + name else: