http-client-branch: Fix for 8198716: Preserve URI component escaped octets when converting to HTTP headers http-client-branch
authorchegar
Tue, 27 Feb 2018 14:45:49 +0000
branchhttp-client-branch
changeset 56200 d712a6342387
parent 56199 681a3e27af10
child 56201 533a1310dc46
http-client-branch: Fix for 8198716: Preserve URI component escaped octets when converting to HTTP headers
src/java.net.http/share/classes/jdk/internal/net/http/Http1Request.java
src/java.net.http/share/classes/jdk/internal/net/http/Stream.java
test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http1Request.java	Tue Feb 27 14:38:17 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http1Request.java	Tue Feb 27 14:45:49 2018 +0000
@@ -114,8 +114,8 @@
     }
 
     private String getPathAndQuery(URI uri) {
-        String path = uri.getPath();
-        String query = uri.getQuery();
+        String path = uri.getRawPath();
+        String query = uri.getRawQuery();
         if (path == null || path.equals("")) {
             path = "/";
         }
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Stream.java	Tue Feb 27 14:38:17 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Stream.java	Tue Feb 27 14:45:49 2018 +0000
@@ -570,8 +570,8 @@
         // TODO: userinfo deprecated. Needs to be removed
         hdrs.setHeader(":authority", uri.getAuthority());
         // TODO: ensure header names beginning with : not in user headers
-        String query = uri.getQuery();
-        String path = uri.getPath();
+        String query = uri.getRawQuery();
+        String path = uri.getRawPath();
         if (path == null || path.isEmpty()) {
             if (method.equalsIgnoreCase("OPTIONS")) {
                 path = "*";
--- a/test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java	Tue Feb 27 14:38:17 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java	Tue Feb 27 14:45:49 2018 +0000
@@ -331,8 +331,9 @@
             nextstream = 1;
         }
 
-        System.out.println("ServerSettings: " + serverSettings);
-        System.out.println("ClientSettings: " + clientSettings);
+        // Uncomment if needed, but very noisy
+        //System.out.println("ServerSettings: " + serverSettings);
+        //System.out.println("ClientSettings: " + clientSettings);
 
         hpackOut = new Encoder(serverSettings.getParameter(HEADER_TABLE_SIZE));
         hpackIn = new Decoder(clientSettings.getParameter(HEADER_TABLE_SIZE));
@@ -487,9 +488,9 @@
         headers.setHeader(":method", tokens[0]);
         headers.setHeader(":scheme", "http"); // always in this case
         headers.setHeader(":authority", host);
-        String path = uri.getPath();
-        if (uri.getQuery() != null)
-            path = path + "?" + uri.getQuery();
+        String path = uri.getRawPath();
+        if (uri.getRawQuery() != null)
+            path = path + "?" + uri.getRawQuery();
         headers.setHeader(":path", path);
 
         Queue q = new Queue(sentinel);
@@ -604,6 +605,7 @@
         } catch (Throwable e) {
             System.err.println("TestServer: handleRequest exception: " + e);
             e.printStackTrace();
+            close(-1);
         }
     }