7005016: sqe test jhttp/HttpServer150013/HttpServer150013.java
authormichaelm
Tue, 07 Dec 2010 13:27:02 +0000
changeset 7537 b7d2d2428f31
parent 7290 15905ab1a64a
child 7538 e7916d8751e0
7005016: sqe test jhttp/HttpServer150013/HttpServer150013.java Reviewed-by: chegar
jdk/src/share/classes/sun/net/httpserver/Request.java
jdk/src/share/classes/sun/net/httpserver/SSLStreams.java
jdk/src/share/classes/sun/net/httpserver/ServerConfig.java
jdk/test/com/sun/net/httpserver/Test10.java
--- a/jdk/src/share/classes/sun/net/httpserver/Request.java	Mon Nov 22 16:11:13 2010 +0000
+++ b/jdk/src/share/classes/sun/net/httpserver/Request.java	Tue Dec 07 13:27:02 2010 +0000
@@ -129,9 +129,22 @@
         hdrs = new Headers();
 
         char s[] = new char[10];
+        int len = 0;
+
         int firstc = is.read();
+
+        // check for empty headers
+        if (firstc == CR || firstc == LF) {
+            int c = is.read();
+            if (c == CR || c == LF) {
+                return hdrs;
+            }
+            s[0] = (char)firstc;
+            len = 1;
+            firstc = c;
+        }
+
         while (firstc != LF && firstc != CR && firstc >= 0) {
-            int len = 0;
             int keyend = -1;
             int c;
             boolean inKey = firstc > ' ';
@@ -191,6 +204,7 @@
             else
                 v = String.copyValueOf(s, keyend, len - keyend);
             hdrs.add (k,v);
+            len = 0;
         }
         return hdrs;
     }
--- a/jdk/src/share/classes/sun/net/httpserver/SSLStreams.java	Mon Nov 22 16:11:13 2010 +0000
+++ b/jdk/src/share/classes/sun/net/httpserver/SSLStreams.java	Tue Dec 07 13:27:02 2010 +0000
@@ -74,8 +74,8 @@
     private void configureEngine(HttpsConfigurator cfg, InetSocketAddress addr){
         if (cfg != null) {
             Parameters params = new Parameters (cfg, addr);
+//BEGIN_TIGER_EXCLUDE
             cfg.configure (params);
-//BEGIN_TIGER_EXCLUDE
             SSLParameters sslParams = params.getSSLParameters();
             if (sslParams != null) {
                 engine.setSSLParameters (sslParams);
--- a/jdk/src/share/classes/sun/net/httpserver/ServerConfig.java	Mon Nov 22 16:11:13 2010 +0000
+++ b/jdk/src/share/classes/sun/net/httpserver/ServerConfig.java	Tue Dec 07 13:27:02 2010 +0000
@@ -42,7 +42,7 @@
     static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec.
 
     /* These values must be a reasonable multiple of clockTick */
-    static final long DEFAULT_IDLE_INTERVAL = 300 ; // 5 min
+    static final long DEFAULT_IDLE_INTERVAL = 30 ; // 5 min
     static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ;
 
     static final long DEFAULT_MAX_REQ_TIME = -1; // default: forever
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/net/httpserver/Test10.java	Tue Dec 07 13:27:02 2010 +0000
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 7005016
+ * @summary  pit jdk7 b121  sqe test jhttp/HttpServer150013 failing
+ * @run main/othervm -Dsun.net.httpserver.clockTick=1000 -Dsun.net.httpserver.idleInterval=3 Test10
+ */
+
+import com.sun.net.httpserver.*;
+
+import java.io.*;
+import java.net.*;
+import java.util.concurrent.*;
+
+/*
+ * Test handling of empty Http headers
+ */
+
+public class Test10 extends Test {
+    public static void main (String[] args) throws Exception {
+        System.out.print ("Test10: ");
+        Handler handler = new Handler();
+        InetSocketAddress addr = new InetSocketAddress (0);
+        HttpServer server = HttpServer.create (addr, 0);
+        int port = server.getAddress().getPort();
+        HttpContext c2 = server.createContext ("/test", handler);
+
+        ExecutorService exec = Executors.newCachedThreadPool();
+        server.setExecutor (exec);
+        try {
+            server.start ();
+            doClient(port);
+            System.out.println ("OK");
+        } finally {
+            delay();
+            if (server != null)
+                server.stop(2);
+            if (exec != null)
+                exec.shutdown();
+        }
+    }
+
+    static class Handler implements HttpHandler {
+        volatile int invocation = 0;
+        public void handle (HttpExchange t)
+            throws IOException
+        {
+            InputStream is = t.getRequestBody();
+            while (is.read() != -1);
+            Headers map = t.getRequestHeaders();
+            t.sendResponseHeaders (200, -1);
+            t.close();
+        }
+    }
+
+    public static void doClient (int port) throws Exception {
+        String s = "GET /test/1.html HTTP/1.1\r\n\r\n";
+
+        Socket socket = new Socket ("localhost", port);
+        OutputStream os = socket.getOutputStream();
+        os.write (s.getBytes());
+        socket.setSoTimeout (10 * 1000);
+        InputStream is = socket.getInputStream();
+        int c;
+        byte[] b = new byte [1024];
+        while ((c=is.read(b)) != -1) ;
+        is.close();
+        socket.close();
+    }
+}