Return-Path: Delivered-To: apmail-hc-dev-archive@www.apache.org Received: (qmail 52746 invoked from network); 8 Jun 2010 15:28:39 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Jun 2010 15:28:39 -0000 Received: (qmail 92082 invoked by uid 500); 8 Jun 2010 15:28:38 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 92041 invoked by uid 500); 8 Jun 2010 15:28:38 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 91941 invoked by uid 99); 8 Jun 2010 15:28:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jun 2010 15:28:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jun 2010 15:28:35 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o58FSDdC001008 for ; Tue, 8 Jun 2010 15:28:13 GMT Message-ID: <1864815.26731276010893145.JavaMail.jira@thor> Date: Tue, 8 Jun 2010 11:28:13 -0400 (EDT) From: =?utf-8?Q?Thierry_Gu=C3=A9rin_=28JIRA=29?= To: dev@hc.apache.org Subject: [jira] Created: (HTTPCLIENT-951) Incorrect handling of InputStreams when connecting to a server that requires authentication MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org Incorrect handling of InputStreams when connecting to a server that require= s authentication ---------------------------------------------------------------------------= ---------------- Key: HTTPCLIENT-951 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-951 Project: HttpComponents HttpClient Issue Type: Bug Components: HttpClient Affects Versions: 4.1 Alpha2, 4.1 Alpha1, 4.0.1, 4.0 Final Environment: Windows XP, Java 1.6.20 Reporter: Thierry Gu=C3=A9rin Attachments: httpClient.diff, httpCore.diff I'm trying to upload a file to a WebDav server (mod_dav on Apache Web Serve= r 2.2.14) that has basic (or digest, the result is the same) authentication= enabled. I'm using the following code: String url =3D "http://myserver/dir/test2.gif"; File file =3D new File("d:/test2.gif"); DefaultHttpClient httpClient =3D new DefaultHttpClient(); HttpPut put =3D new HttpPut(url); put.setEntity(new InputStreamEntity(new FileInputStream(file), file= .length())); =20 URI uri =3D put.getURI(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(ur= i.getHost(), uri.getPort()), getCredentials()); put.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_C= ONTINUE, true); HttpResponse response =3D httpClient.execute(put); System.out.println(response.getStatusLine()); When running the above code, I'm getting a org.apache.http.client.NonRepeat= ableRequestException: Cannot retry request with a non-repeatable request en= tity. I tested both the latest alpha & the svn head. Doing the same thing i= n HttpClient 3.1 worked as expected.=20 This could be normal, as I'm using an InputStream that is indeed not repeat= able, but as I'm also using Expect: 100-Continue, the stream shouldn't have= been consumed with the first connection (the one that gets a code 401 from= the WebDav server), and only in the second one, when the credentials are p= rovided. The problem is that DefaultRequestDirector.execute doesn't take this into a= ccount and assumes that if a request has been tried once, its associated en= tity (if any) has been consumed. Here's the fix that I came up with: Change DefaultRequestDirector.execute so that if the wrapper is an EntityEn= closingRequestWrapper, it checks if the entity has actually been consumed b= efore throwing a NonRepeatableRequestException. I'm using the method isStre= aming() from HttpEntity, as it's the closest thing to what I was looking fo= r. Reading the JavaDoc, it could lead to the situation where an entity has = started streaming but has not yet finished, and so is not in a state where = it can be used. However I don't think that's a problem as the javadoc for H= ttpEntity.getContent() states that it can't be called two times on a non-re= peatable entity, so it's just a matter of when the request will fail. This lead me to also modify InputStreamEntity (from the httpCore project) a= s it didn't comply with the javadoc. With these two modifications, The file= upload completes successfully. I also modified: * TestInputStreamEntity.testBasics() (from the httpCore project) test so t= hat it complies with getContent()'s Javadoc. * TestDefaultClientRequestDirector.FaultyHttpRequestExecutor because it di= dn't consume the entity's content. All the tests from both httpCore and httpClient pass. I tested both InputStreamEntity and BasicHttpEntity. =20 Please keep in mind that I am by no means an httpClient (or http, for that = matter) expert, and these modifications may have some unexpected side-effec= ts that I did not foresee, contain plain dumb code, or whatever, so it woul= d be great if someone could review my changes and give their opinion. --=20 This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org