Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 35CD2851 for ; Fri, 24 Aug 2012 14:02:54 +0000 (UTC) Received: (qmail 40877 invoked by uid 500); 24 Aug 2012 14:02:53 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 40778 invoked by uid 500); 24 Aug 2012 14:02:53 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 40766 invoked by uid 99); 24 Aug 2012 14:02:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Aug 2012 14:02:52 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of david.mencarelli@ezcgroup.net designates 178.32.228.2 as permitted sender) Received: from [178.32.228.2] (HELO mo2.mail-out.ovh.net) (178.32.228.2) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Aug 2012 14:02:43 +0000 Received: from mail641.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo2.mail-out.ovh.net (Postfix) with SMTP id 0C761DC13FD for ; Fri, 24 Aug 2012 16:07:21 +0200 (CEST) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 24 Aug 2012 16:02:51 +0200 Received: from unknown (HELO ?192.168.178.34?) (david.mencarelli@ezcgroup.net@83.99.17.140) by ns0.ovh.net with SMTP; 24 Aug 2012 16:02:51 +0200 From: David Mencarelli Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Ovh-Mailout: 178.32.228.2 (mo2.mail-out.ovh.net) Subject: Abort a PUT request when server sends an error Date: Fri, 24 Aug 2012 16:02:20 +0200 Message-Id: <1AFB1EAF-C0FC-415D-A0EE-3F8044C0D88D@ezcgroup.net> To: httpclient-users@hc.apache.org Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-Ovh-Tracer-Id: 9911015405636458000 X-Ovh-Remote: 83.99.17.140 () X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: 0 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehtddrvdehucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpeffrghvihguucfovghntggrrhgvlhhlihcuoegurghvihgurdhmvghntggrrhgvlhhlihesvgiitghgrhhouhhprdhnvghtqeenucffohhmrghinhephhhtthhptghlihgvnhhtrdgvgigvtghuthgvpdhhthhtphhsvghrvhhlvghtrhgvshhpohhnshgvrdhstgenucfjughrpefhtgfgufffkffvggfosehtqhertdhhtddv X-Spam-Check: DONE|U 0.500004/N X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehtddrvdehucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpeffrghvihguucfovghntggrrhgvlhhlihcuoegurghvihgurdhmvghntggrrhgvlhhlihesvgiitghgrhhouhhprdhnvghtqeenucffohhmrghinhephhhtthhptghlihgvnhhtrdgvgigvtghuthgvpdhhthhtphhsvghrvhhlvghtrhgvshhpohhnshgvrdhstgenucfjughrpefhtgfgufffkffvggfosehtqhertdhhtddv X-Virus-Checked: Checked by ClamAV on apache.org 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 =3D new HttpPut(destination); InputStreamEntity entity =3D new InputStreamEntity(inputStream, = contentLength); ((HttpPut)httpRequest).setEntity(entity); httpClient.execute(httpRequest,handler); It worked fine.=20 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.=20 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 --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org For additional commands, e-mail: httpclient-users-help@hc.apache.org