You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Paulex Yang (JIRA)" <ji...@apache.org> on 2006/08/18 04:20:15 UTC

[jira] Closed: (HARMONY-1189) [classlib][luni] java.net.HttpURLConnection.getHeaderFieldXXX family methods return incorrect value when http server replied bad response code.

     [ http://issues.apache.org/jira/browse/HARMONY-1189?page=all ]

Paulex Yang closed HARMONY-1189.
--------------------------------


Verified by Andrew.

> [classlib][luni] java.net.HttpURLConnection.getHeaderFieldXXX family methods return incorrect value when http server replied bad response code.
> -----------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1189
>                 URL: http://issues.apache.org/jira/browse/HARMONY-1189
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Andrew Zhang
>         Assigned To: Paulex Yang
>         Attachments: Harmony-1189.diff
>
>
> java.net.HttpURLConnection.getHeaderField family method returns incorrect value when http server replies bad response code.
> Following test reproduces the bug (Not stable though):
> public void test_getHeaderField() throws Exception {
>         MockServer server = new MockServer();
>         URL u = new URL("http://127.0.0.1:" + server.getLocalPort());
>         server.start();
>         Thread.sleep(1000);
>         HttpURLConnection conn = (HttpURLConnection) u.openConnection();
>         assertEquals("text/html", conn.getHeaderField("content-type"));
>         assertEquals("1234", conn.getHeaderField("content-length"));
>         assertEquals("text/html", conn.getHeaderField(2));
>         assertEquals("1234", conn.getHeaderField(3));
>         assertEquals("Content-Type", conn.getHeaderFieldKey(2));
>         assertEquals("Content-Length", conn.getHeaderFieldKey(3));
>         Map<String, List<String>> fields = conn.getHeaderFields();
>         assertNotNull(fields);
>     }
>     private class MockServer extends Thread {
>         ServerSocket ss;
>         Socket client;
>         MockServer() throws Exception {
>             ss = new ServerSocket(0);
>         }
>         public void run() {
>             try {
>                 client = ss.accept();
>                 OutputStream os = client.getOutputStream();
>                 String content = "HTTP/1.1 404 Page Not Found\r\npath=/; domain=apache.com\r\nContent-Type: text/html\r\nContent-Length: 1234\r\n\r\n<html><body></body></html>";
>                 os.write(content.getBytes("ISO-8859-1"));
>                 // os.close();
>             } catch (IOException e) {
>             } finally {
>                 try {
>                     client.close();
>                 } catch (Exception e) {
>                     // ignore
>                 }
>                 try {
>                     ss.close();
>                 } catch (Exception e) {
>                     // ignore
>                 }
>             }
>         }
>         int getLocalPort() {
>             return ss.getLocalPort();
>         }
>     }
> The test passes against RI while fails against Harmony.
> I'll upload a patch to solve this problem soon, but without test, because the test depends on multi-thread race. 
> Thanks!
> Best regards,
> Andrew

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira