On Fri, 2012-08-24 at 16:02 +0200, David Mencarelli wrote: > Hello, > > I'm using httpclient-4 (more precisely 4.1.2) to send the content of a stream > (a huge file in this case) to my Tomcat's upload servlet using the following > code: > > HttpRequest httpRequest = new HttpPut(destination); > InputStreamEntity entity = new InputStreamEntity(inputStream, contentLength); > ((HttpPut)httpRequest).setEntity(entity); > httpClient.execute(httpRequest,handler); > > It worked fine. > > I later added an authentication mechanism to prevent unauthorized user to > upload files. If someone tries to upload without being authenticated the > servlet directly responds with an HttpServletResponse.SC_FORBIDDEN without > even processing the request's InputStream. > > The problem I am facing is that despite the fact that the request is rejected > on the server side, my client keeps sending the whole content of the > InputStream resulting in a waste of network resources. > > Here is a sample trace of execution: > 12:00:32,813 -> call to execute > 12:00:32:936 -> server sends an SC_FORBIDDEN error > 12:00:44:883 -> response handler execute (and I detect the SC_FORBIDDEN > status) > Network activity shows that the whole content of the file has been sent on > the line. > > I have tried several server sides trick like reading one byte of the input > stream then closing it but nothing worked. > > Is there a way to tell the httpclient to stop streaming the content of the > file when the response is forbidden (or any other status different of 200) ? > > Any insights will be appreciated. > > Thanks! > > Regards, > David >
David The 'expect: continue' handshake is your friend. This is precisely what it is intended for: to ensure requests meets the server expectations. It is disabled per default. Try turning it on. Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
