Skip to content

POST will hang at execute #83

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

Open
kensee opened this issue Feb 6, 2016 · 15 comments
Open

POST will hang at execute #83

kensee opened this issue Feb 6, 2016 · 15 comments
Labels

Comments

@kensee
Copy link

kensee commented Feb 6, 2016

Hi,

I created a simple form to do a POST and it hang at proxyResponse = proxyClient.execute. GET is working fine.

Anyone having the same issue? or am I missing something.

@IgnasD
Copy link

IgnasD commented Mar 10, 2016

Hello,

Same here. Have no idea what's wrong. It's a shame since it is the only HTTP reverse proxy servlet I could find.

@dsmiley
Copy link
Collaborator

dsmiley commented Mar 10, 2016

Please debug it. Perhaps an older version of this proxy didn't have this problem? Maybe it's sensitive to which HttpClient is used?

@kensee
Copy link
Author

kensee commented Mar 10, 2016

Seems like the way it handle POST is broken. Had to change it to handle multipart and standard POST.

@IgnasD
Copy link

IgnasD commented Mar 13, 2016

Sorry for the delayed response.

@kensee, if I understood you correctly, it seems that you have already done all the debugging. If so, could you share the solution?

@IgnasD
Copy link

IgnasD commented Mar 14, 2016

@dsmiley, so I did some debugging and in my case it is dup of #54.

OrderedHiddenHttpMethodFilter of Spring Boot is calling getParameter and body of the request gets consumed. So when proxy calls getInputStream, it gets blank input.

InputStreamEntity is created with explicitly specified content length, which is non-zero, so InputStreamEntity tries to read specified byte count indefinitely thus creating the hang effect.

@dsmiley
Copy link
Collaborator

dsmiley commented Mar 14, 2016

Aaaah; yes. This is not a bug but a.... "gotcha", if you will, with knowing how not to use this servlet. If you can suggest a work-around for Spring Boot in particular, or can surmise how the proxy itself might better handle this, I welcome your input.

@IgnasD
Copy link

IgnasD commented Mar 15, 2016

Well, in my case, disabling WebMvcAutoConfiguration was acceptable solution:
@SpringBootApplication(exclude = { WebMvcAutoConfiguration.class })

About handling this situation better in proxy side, I have no ideas that I like.

@kuun
Copy link

kuun commented Nov 23, 2016

The proxy can't handle 100 continue, if the post contains header 'Expect: 100 continue', it can't forward request body to server.

@dsmiley
Copy link
Collaborator

dsmiley commented Nov 23, 2016

@kuun do you believe your comment applies to the O.P.'s issue? If you're not sure then please file a new issue. I ought to close this one, I think.

@luxmentis
Copy link

My solution to the Spring Boot problem was to refactor the proxy code so it could be called from a filter. You also need to make sure the filter executes before Spring's ones: use a FilterRegistrationBean and set order = Integer.MIN_VALUE.
Although I guess it's nice to have all the code in one file, it'd be more flexible to provide a filter as well as a servlet. Most of the code would be shared. (I wonder if I've missed any gotchas. We'll see.)

@dsmiley
Copy link
Collaborator

dsmiley commented Mar 4, 2017

@Seldomseenkid Although I want the core servlet to be stand-alone (one source file), I'm open to the idea of adding a separate HttpProxyServletFilter class that has a reference to ProxyServlet (or URITemplateProxyServlet) to do the vast majority of the work. I'm not sure of the details to know if this makes sense or not.

@chambjl
Copy link

chambjl commented Jun 8, 2017

I was able to resolve this issue in my project by disabling HiddenHttpMethodFilter, as follows:

    @Bean
    public FilterRegistrationBean registration(HiddenHttpMethodFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean(filter);
        registration.setEnabled(false);
        return registration;
    }

That particular solution was found here: https://stackoverflow.com/questions/8522568/why-is-httpservletrequest-inputstream-empty

Spring Boot version: 1.4.1.RELEASE

@eis
Copy link

eis commented Mar 15, 2018

Yes! Disabling HiddenHttpMethodFilter worked for me too.

eis added a commit to eis/spring-proxy that referenced this issue Mar 15, 2018
dsmiley added a commit that referenced this issue Mar 16, 2018
smjie2800 added a commit to smjie2800/spring-cloud-microservice-redis-activemq-hibernate-mysql that referenced this issue Apr 20, 2018
@Nisus-Liu
Copy link

I looked HiddenHttpMethodFilter, but I did not see what 'bad things' it did??
Follow code is part of HiddenHttpMethodFilter.

	@Override
	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
			throws ServletException, IOException {

		HttpServletRequest requestToUse = request;

		if ("POST".equals(request.getMethod()) && request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) == null) {
			String paramValue = request.getParameter(this.methodParam);
			if (StringUtils.hasLength(paramValue)) {
				requestToUse = new HttpMethodRequestWrapper(request, paramValue);
			}
		}

		filterChain.doFilter(requestToUse, response);
	}

@dsmiley
Copy link
Collaborator

dsmiley commented Dec 27, 2018

It calls request.getParameter which looks super innocent but it has a side-effect of consuming the POST'ed input stream. See it's javadocs.

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

No branches or pull requests

8 participants