Skip to content

fix : restore wsgi.input stream after middleware body read so request.get_json() works in views - #201

Open
0x070907 wants to merge 1 commit into
0-Shimanshu:mainfrom
0x070907:fix/restore-wsgi-input-after-middleware-read
Open

fix : restore wsgi.input stream after middleware body read so request.get_json() works in views#201
0x070907 wants to merge 1 commit into
0-Shimanshu:mainfrom
0x070907:fix/restore-wsgi-input-after-middleware-read

Conversation

@0x070907

Copy link
Copy Markdown
Contributor

Summary

Closes #185

The fix reads environ["wsgi.input"] directly before Request(environ) is called, then immediately restores it with a fresh BytesIO. Flask's Request then wraps the restored stream and request.get_json() works correctly.

Why

Any Flask view that calls request.get_json() or request.get_data(), after the middleware ran, would silently receive an empty body. The bug was hidden in existing tests because no test view ever read the request body.

Scope

  • bug fix
  • documentation
  • tests
  • TUI / CLI improvement
  • framework integration
  • signal change
  • configuration or route-policy change

Changes

adiuvare/integrations/flask.py - Added import io, moved body reading before Request(environ), restored wsgi.input with BytesIO
tests/test_flask.py - Added test_flask_request_json_readable_after_middleware_inspection


Verification

Commands run:

pip install -e .

pytest tests/test_flask.py::test_flask_request_json_readable_after_middleware_inspection -v

Screenshots

before the fix

image

after the fix

image

Notes:

  • I ran the relevant tests locally
  • I updated docs if behavior changed
  • I updated screenshots if the TUI changed materially

Signal-specific notes

  • not applicable

TUI notes

  • not applicable

Local-only file check

  • I did not accidentally stage local-only files such as adiuvare.yaml or local conftest.py changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Flask views cannot read JSON body after middleware inspection

1 participant