Skip to content

Support for PUTting form-encoded data [SPR-5628] #10299

Closed
@spring-projects-issues

Description

@spring-projects-issues

Grzegorz Borkowski opened SPR-5628 and commented

In RESTful services scenario it is not uncommon to accept the incoming data (as service input) in the form-encoded format (Content-type: application/x-www-form-urlencoded). This format is well-known, popular, implemented in every language. See the RESTful Web Service book from O'Reilly for longer discussion of such choice.
Obviously, REST service will accept form-endoded data in POST and PUT request. The problem is that servlet spec (or implementations) seems to be broken in this area. HttpServletRequest.getParameter("foo") method for form-encoded data returns the parameter value only for POST requests, not for PUT. I've tested it on Tomcat and Glassfish.
This also means that all Spring's autobinding features (with command object) will fail for PUT requests. This is really serious problem, as for PUT requests, one have to manually parse and decode the request body.
The solution would be I think to add some filter, which wraps the request when the method is PUT and content type is "application/x-www-form-urlencoded", and override the getParameter() and related methods.
It would be probably also helpful to check the servlet spec for explanation of this behavior, and how it is implemented in Tomcat (or other containers).

To reproduce, simply create servlet or JSP like this:
<%=request.getParameter("foo")%>
and send POST and then PUT request to it, with content-type set to "application/x-www-form-urlencoded" and body equal to "foo=bar"


Affects: 3.0 M3

Issue Links:

Referenced from: commits d746dca, 2cf2fc1

4 votes, 7 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions