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

HiddenHttpMethodFilter cause HttpServletRequest.getInputStream() is empty #5676

Closed
mrleoyoung opened this issue Apr 13, 2016 · 3 comments
Closed
Labels
status: invalid An issue that we don't feel is valid

Comments

@mrleoyoung
Copy link

org.springframework.web.filter.HiddenHttpMethodFilter, String paramValue = request.getParameter(this.methodParam); cause HttpServletRequest.getInputStream() will be empty in future.
and the filter is introduced by org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration, which is automatically enabled when using spring mvc in spring-boot

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 13, 2016
@wilkinsona
Copy link
Member

HttpServletRequest.getInputStream() will be empty in future.

I don't believe that's always the case. AFAIK, the input stream will only be empty if it was a POST request with a content type of multipart/form-data or application/x-www-form-url-encoded. In those cases, the request's body is then available via getParameters() or getParts() so there's typically no need to use the input stream.

Can you provide some more information about the container that you're using, the type of request that you are sending, and why you need to use the input stream?

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 13, 2016
@mrleoyoung
Copy link
Author

Well, I think a framework should not consume the IO data that can be consumed only once. We have a file sync service. when a file is ready, we use curl to post the file to our service. some thing like this:
my test post:
curl -X POST -H "Expect:" --data-binary @"test.jpg" "http://localhost:7001/upload"
my simple servlet in spring boot(spring mvc):
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(request.getInputStream(), outputStream); byte[] data = outputStream.toByteArray();

actually, this issue is trying to fix the same problem as this one: https://github.com/spring-projects/spring-boot/commit/607dba97f8e3d69517924431678179b003d3d4a5

thanks.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 14, 2016
@wilkinsona
Copy link
Member

curl -X POST -H "Expect:" --data-binary @"test.jpg" "http://localhost:7001/upload"

This will upload the JPEG image using application/x-www-form-urlencoded as the Content-Type. That almost certainly isn't what you want and you'll see Tomcat fail to parse the parameters with an INFO message that begins:

2016-04-14 11:12:09.056  INFO 36165 --- [nio-8080-exec-3] org.apache.tomcat.util.http.Parameters   : Character decoding failed. Parameter

If you want to access the image data directly via the InputStream you should explicitly set the Content-Type:

curl http://localhost:7001/upload -H "Content-Type: image/jpeg" --data-binary @test.jpg 

Alternatively, you can make the data available via the request's parts by uploading it as multipart/form-data:

curl http://localhost:8080/upload -F image=@test.jpg

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: feedback-provided Feedback has been provided labels Apr 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants