http-client-branch: review comment: make test HTTP/2 server more tollerant of bad connections http-client-branch
authorchegar
Wed, 06 Dec 2017 12:15:54 +0000
branchhttp-client-branch
changeset 55961 896f012552ca
parent 55960 7553e90ba43c
child 55964 b2e6f2945ac3
http-client-branch: review comment: make test HTTP/2 server more tollerant of bad connections
test/jdk/java/net/httpclient/http2/server/Http2TestServer.java
test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java
--- a/test/jdk/java/net/httpclient/http2/server/Http2TestServer.java	Wed Dec 06 12:11:36 2017 +0000
+++ b/test/jdk/java/net/httpclient/http2/server/Http2TestServer.java	Wed Dec 06 12:15:54 2017 +0000
@@ -219,19 +219,20 @@
                     connections.put(addr, c);
                     try {
                         c.run();
-                    } catch(Throwable e) {
+                    } catch (Throwable e) {
                         // we should not reach here, but if we do
                         // the connection might not have been closed
                         // and if so then the client might wait
                         // forever.
                         connections.remove(addr, c);
                         c.close(ErrorFrame.PROTOCOL_ERROR);
-                        throw e;
+                        System.err.println("TestServer: start exception: " + e);
+                        //throw e;
                     }
                 }
             } catch (Throwable e) {
                 if (!stopping) {
-                    System.err.println("TestServer: start exception: " + e);
+                    System.err.println("TestServer: terminating, caught " + e);
                     e.printStackTrace();
                 }
             }
--- a/test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java	Wed Dec 06 12:11:36 2017 +0000
+++ b/test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java	Wed Dec 06 12:15:54 2017 +0000
@@ -888,17 +888,23 @@
     String readHttp1Request() throws IOException {
         String headers = readUntil(CRLF + CRLF);
         int clen = getContentLength(headers);
-        byte[] buf;
-        if (clen >= 0) {
-            // HTTP/1.1 fixed length content ( may be 0 ), read it
-            buf = new byte[clen];
-            is.readNBytes(buf, 0, clen);
-        } else {
-            //  HTTP/1.1 chunked data, read it
-            buf = readChunkedInputStream(is);
+        String te = getHeader(headers, "Transfer-encoding");
+        byte[] buf = new byte[0];
+        try {
+            if (clen >= 0) {
+                // HTTP/1.1 fixed length content ( may be 0 ), read it
+                buf = new byte[clen];
+                is.readNBytes(buf, 0, clen);
+            } else if ("chunked".equalsIgnoreCase(te)) {
+                //  HTTP/1.1 chunked data, read it
+                buf = readChunkedInputStream(is);
+            }
+            String body = new String(buf, StandardCharsets.US_ASCII);
+            return headers + body;
+        } catch (IOException e) {
+            System.err.println("TestServer: headers read: [ " + headers + " ]");
+            throw e;
         }
-        String body = new String(buf, StandardCharsets.US_ASCII);
-        return headers + body;
     }
 
     // This is a quick hack to get a chunked input stream reader.