Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tornado.httputil.HTTPServerRequest and tornado.web.RequestHandler #3369

Open
Stronking opened this issue Apr 10, 2024 · 1 comment
Open

tornado.httputil.HTTPServerRequest and tornado.web.RequestHandler #3369

Stronking opened this issue Apr 10, 2024 · 1 comment
Labels

Comments

@Stronking
Copy link

In the tornado.httputil.HTTPServerRequest class, why is the body_arguments attribute initialized as an empty dictionary {}? This design choice necessitates developers to manually parse the request.body when handling POST request bodies, and it precludes the use of parameter assertions. Consequently, when utilizing the tornado.web.RequestHandler.get_body_arguments methods, a MissingArgumentError is consistently thrown if the corresponding parameter is missing from the request body. Will this issue be addressed or improved in future versions?

This problem can hinder user experience and code robustness, especially for developers who are new to the Tornado framework. It may increase the difficulty of understanding and using the framework. It would be appreciated if the development team could consider optimizing this issue or providing clearer documentation on how to handle it.

@bdarnell
Copy link
Member

why is the body_arguments attribute initialized as an empty dictionary {}?

What alternative do you have in mind?

This design choice necessitates developers to manually parse the request.body when handling POST request bodies,

Ah, are you talking about parsing JSON or other body formats? The (query|body)_argument(s) attributes and methods are specific to HTML forms, and they inherit a lot of quirks from the limitations of the form-encoded format. If you're using something other than HTML form-encoded data, just ignore all of this and do something like self.json_args = parse(self.request.body) in an override of prepare().

Will this issue be addressed or improved in future versions?

I have no plans for changes here. I have vague interest in some sort of middleware scheme that would let you centralize request parsing but no concrete plans.

Nirab123456 added a commit to Nirab123456/tornado-RequestParsingMiddleware that referenced this issue Oct 18, 2024
…verRequest and RequestHandler. Enhanced support for JSON, form-encoded, and multipart data, including file uploads. Updated unit tests to cover all scenarios, ensuring robust handling of requests.
Nirab123456 added a commit to Nirab123456/tornado-RequestParsingMiddleware that referenced this issue Oct 18, 2024
…verRequest and RequestHandler. Enhanced support for JSON, form-encoded, and multipart data, including file uploads. Updated unit tests to cover all scenarios, ensuring robust handling of requests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants