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

Proposal: "getQueries()" should be refactored as a high-priotity layer #57

Open
jankeromnes opened this issue Jan 14, 2017 · 0 comments

Comments

@jankeromnes
Copy link
Collaborator

Current situation: Most camp layers (which I like to call "middlewares") call getQueries() at some point to, when it makes sense, retrieve and parse additional information about a request (e.g. POST data). This call may happen multiple times as a request moves through several layers (although a single call would be enough to populate request.query with all the data).

Problem: This causes "external middlewares" (new layers added with camp.handle()) to be called with an incomplete request.query (e.g. when a handler expects data sent via POST request, the data won't be available in the request.query it receives, because internally getQueries() will be called after the handler if at all).

Workaround: "external middlewares" don't have access to getQueries(), so they may re-implement its behavior by means of request.on("data") and request.on("end") listeners.

Suggested improvement: I think that getQueries() should actually be called only once, before any other layers (including camp.handle() layer), so that all layers have equal access to parsed POST data. Or getQueries could be called asynchronously, and handlers should have a wait to wait for its results to be available in order to process it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant