Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 56773 invoked from network); 3 Sep 2010 20:32:58 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 3 Sep 2010 20:32:58 -0000 Received: (qmail 57192 invoked by uid 500); 3 Sep 2010 20:32:58 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 57147 invoked by uid 500); 3 Sep 2010 20:32:58 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 57064 invoked by uid 99); 3 Sep 2010 20:32:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Sep 2010 20:32:58 +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; Fri, 03 Sep 2010 20:32:55 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o83KWYq9024910 for ; Fri, 3 Sep 2010 20:32:34 GMT Message-ID: <11068873.18781283545954144.JavaMail.jira@thor> Date: Fri, 3 Sep 2010 16:32:34 -0400 (EDT) From: "Rainer Burgstaller (JIRA)" To: commits@harmony.apache.org Subject: [jira] Created: (HARMONY-6643) HTTP 401 status code closes HttpUrlConnectionImpl and causes retries when calling getHeaderField() methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org HTTP 401 status code closes HttpUrlConnectionImpl and causes retries when calling getHeaderField() methods ---------------------------------------------------------------------------------------------------------- Key: HARMONY-6643 URL: https://issues.apache.org/jira/browse/HARMONY-6643 Project: Harmony Issue Type: Bug Components: Classlib Environment: Android 2.2 as well as trunk code inspection Reporter: Rainer Burgstaller The following code will force 2 HTTP requests being sent to the server URL url = new URL("http://server/that/sends/401"); HttpURLConnection cn = (HttpURLConnection) url.openConnection(); int rc = cn.getResponseCode(); // This will cause the first request/response cycle // now cn.connected will be false Map> map = m_cn.getRequestProperties(); // This will cause ANOTHER request/response cycle Map> map = m_cn.getRequestProperties(); // This will cause ANOTHER request/response cycle Map> map = m_cn.getRequestProperties(); // This will cause ANOTHER request/response cycle ... The cause of the problem seems to be that doRequestInternal sets its "connected" variable back to false. doRequestInternal() { ... // HTTP authorization failed ? 1415 if (responseCode == HTTP_UNAUTHORIZED) { 1416 // keep asking for username/password until authorized 1417 String challenge = resHeader.get("WWW-Authenticate"); //$NON-NLS-1$ 1418 if (challenge == null) { 1419 break; 1420 } 1421 // drop everything and reconnect, might not be required for 1422 // HTTP/1.1 1423 endRequest(); 1424 disconnect(); => 1425 connected = false; however, getHeaderFieldXXX methods call getInputStream() which will itself call connect() and doRequest(). @Override 854 public Map> getHeaderFields() { 855 try { 856 // ensure that resHeader exists 857 getInputStream(); 75 @Override 876 public InputStream getInputStream() throws IOException { 877 if (!doInput) { 878 throw new ProtocolException(Messages.getString("luni.28")); //$NON-NLS-1$ 879 } 880 881 // connect before sending requests => 882 connect(); 883 doRequest(); Since connected=false and the connection is already considered "reset" every of these methods will again force a complete request/response cycle. Therefore if a user would like to see both the return code as well as all the headers for a request that resultet in a 401, harmony will send AT LEAST 2 requests out. It actually gets even worse when trying to iterate over the response headers. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.