Merge pull request #22108 from mvdbeek/fix_middleware_strings

[26.0] Fix WSGI middlewares returning strings
This commit is contained in:
Marius van den Beek
2026-03-14 18:33:20 +01:00
committed by GitHub
3 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -267,7 +267,7 @@ class CatchingIter:
if not self.start_checker.response_started:
self.start_checker("500 Internal Server Error", [("content-type", "text/html")], exc_info)
return response
return response.encode("utf-8", errors="ignore")
def close(self):
# This should at least print something to stderr if the
@@ -67,7 +67,7 @@ class ProfileMiddleware:
prof = cProfile.Profile()
prof.runctx("run_app()", globals(), locals())
# Build up body with stats
body = "".join(body)
body = b"".join(body)
headers = catch_response[1]
content_type = response.header_value(headers, "content-type")
if not content_type.startswith("text/html"):
@@ -77,7 +77,7 @@ class ProfileMiddleware:
stats.strip_dirs()
stats.sort_stats("time", "calls")
output = pstats_as_html(stats, self.limit)
body += template % output
body += (template % output).encode("utf-8")
return [body]
@@ -54,7 +54,7 @@ class CacheableStaticURLParser(StaticURLParser):
headers: list[tuple[str, str]] = []
ETAG.update(headers, mytime)
start_response("304 Not Modified", headers)
return [""] # empty body
return [b""] # empty body
app = FileApp(full)
if self.cache_seconds:
app.cache_control(max_age=int(self.cache_seconds))