| Description: |
I would like to update the way that ncgi parses requests in relationship to the content type and the HTTP method.
Currently, ncgi treats the "query" as the url encoded parameters or multipart form parameters on stdin depending on if the method is GET or POST, respectively. To populate nvlist, it switches on Content-Type to determine whether to parse query as url params or form data.
This causes issues for anyone using other HTTP methods other than GET or POST, as well as other content types. The current implementation errors out on "unknown content types", including text/plain.
It also makes it difficult to POST data in different formats, like JSON, and impossible to parse both url encoded parameters and form data at the same time.
I am willing to do the work, I just want to see what everyone things before investing time into this.
I have two suggestions for how to improve ncgi:
1) encapsulate the url parameter parsing code in ::ncgi::parse into its own function, allowing the developer to skip calling ::ncgi::parse and instead call ::ncgi::parseUrlParams and ::ncgi::multipart separately, as needed.
2) reorganize ncgi so that query only refers to URL encoded parameters, make ncgi more flexible to other content types and HTTP methods, and split $values into $queryValues and $formValues, with nvlist being a merger or the two.
The advantages to option 1 are that it is easy and backwards compatible. The advantages to 2 are that it is, in my opinion at least, the more correct and complete way to approach the problem.
|