Skip to content

Commit

Permalink
fixup: pr
Browse files Browse the repository at this point in the history
  • Loading branch information
myslak committed Jan 26, 2024
1 parent 8ee43c1 commit 6ff912e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,20 @@ class ProfilingMiddleware(MiddlewareProtocol):

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
profiler = Profiler(interval=0.001, async_mode="enabled")

profiler.start()
profile_html: str | None = None

async def send_wrapper(message: Message) -> None:
if message["type"] == "http.response.body":
message["body"] = profiler.output_html().encode()

elif message["type"] == "http.response.start":
if message["type"] == "http.response.start":
profiler.stop()
nonlocal profile_html
profile_html = profiler.output_html()
message["headers"] = [
(b"content-type", b"text/html; charset=utf-8"),
(b"content-length", str(len(profiler.output_html())).encode()),
(b"content-length", str(len(profile_html)).encode()),
]

elif message["type"] == "http.response.body":
message["body"] = profile_html.encode()
await send(message)

await self.app(scope, receive, send_wrapper)
Expand Down
14 changes: 7 additions & 7 deletions examples/litestar_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ def __init__(self, app: ASGIApp) -> None:

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
profiler = Profiler(interval=0.001, async_mode="enabled")

profiler.start()
profile_html: str | None = None

async def send_wrapper(message: Message) -> None:
if message["type"] == "http.response.body":
message["body"] = profiler.output_html().encode()

elif message["type"] == "http.response.start":
if message["type"] == "http.response.start":
profiler.stop()
nonlocal profile_html
profile_html = profiler.output_html()
message["headers"] = [
(b"content-type", b"text/html; charset=utf-8"),
(b"content-length", str(len(profiler.output_html())).encode()),
(b"content-length", str(len(profile_html)).encode()),
]

elif message["type"] == "http.response.body":
message["body"] = profile_html.encode()
await send(message)

await self.app(scope, receive, send_wrapper)
Expand Down

0 comments on commit 6ff912e

Please sign in to comment.