http-client-branch: make PushPromiseHandlerMap package private http-client-branch
authormichaelm
Fri, 19 Jan 2018 15:05:27 +0000
branchhttp-client-branch
changeset 56031 c52c9a3a2046
parent 56025 1f88e1587067
child 56032 bea253ebd7ac
http-client-branch: make PushPromiseHandlerMap package private
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponse.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponse.java	Thu Jan 18 19:51:17 2018 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponse.java	Fri Jan 19 15:05:27 2018 +0000
@@ -209,6 +209,51 @@
         }
     }
 
+    /* package-private with push promise Map implementation */
+    static class PushPromisesHandlerWithMap<T> implements PushPromiseHandler<T> {
+
+        private final ConcurrentMap<HttpRequest,CompletableFuture<HttpResponse<T>>> pushPromisesMap;
+        private final Function<HttpRequest,BodyHandler<T>> pushPromiseHandler;
+
+        PushPromisesHandlerWithMap(Function<HttpRequest,BodyHandler<T>> pushPromiseHandler,
+                                   ConcurrentMap<HttpRequest,CompletableFuture<HttpResponse<T>>> pushPromisesMap) {
+            this.pushPromiseHandler = pushPromiseHandler;
+            this.pushPromisesMap = pushPromisesMap;
+        }
+
+        @Override
+        public void applyPushPromise(
+            HttpRequest initiatingRequest, HttpRequest pushRequest,
+            Function<BodyHandler<T>,CompletableFuture<HttpResponse<T>>> acceptor)
+        {
+            URI initiatingURI = initiatingRequest.uri();
+            URI pushRequestURI = pushRequest.uri();
+            if (!initiatingURI.getHost().equalsIgnoreCase(pushRequestURI.getHost()))
+                return;
+
+            int initiatingPort = initiatingURI.getPort();
+            if (initiatingPort == -1 ) {
+                if ("https".equalsIgnoreCase(initiatingURI.getScheme()))
+                    initiatingPort = 443;
+                else
+                    initiatingPort = 80;
+            }
+            int pushPort = pushRequestURI.getPort();
+            if (pushPort == -1 ) {
+                if ("https".equalsIgnoreCase(pushRequestURI.getScheme()))
+                    pushPort = 443;
+                else
+                    pushPort = 80;
+            }
+            if (initiatingPort != pushPort)
+                return;
+
+            CompletableFuture<HttpResponse<T>> cf =
+                    acceptor.apply(pushPromiseHandler.apply(pushRequest));
+            pushPromisesMap.put(pushRequest, cf);
+        }
+    }
+
     // Similar to Path body handler, but for file download. Supports setting ACC.
     static class FileDownloadBodyHandler implements UntrustedBodyHandler<Path> {
         private final Path directory;
@@ -772,51 +817,6 @@
         );
 
 
-        /* package-private with push promise Map implementation */
-        static class PushPromisesHandlerWithMap<T> implements PushPromiseHandler<T> {
-
-            private final ConcurrentMap<HttpRequest,CompletableFuture<HttpResponse<T>>> pushPromisesMap;
-            private final Function<HttpRequest,BodyHandler<T>> pushPromiseHandler;
-
-            PushPromisesHandlerWithMap(Function<HttpRequest,BodyHandler<T>> pushPromiseHandler,
-                                       ConcurrentMap<HttpRequest,CompletableFuture<HttpResponse<T>>> pushPromisesMap) {
-                this.pushPromiseHandler = pushPromiseHandler;
-                this.pushPromisesMap = pushPromisesMap;
-            }
-
-            @Override
-            public void applyPushPromise(
-                HttpRequest initiatingRequest, HttpRequest pushRequest,
-                Function<BodyHandler<T>,CompletableFuture<HttpResponse<T>>> acceptor)
-            {
-                URI initiatingURI = initiatingRequest.uri();
-                URI pushRequestURI = pushRequest.uri();
-                if (!initiatingURI.getHost().equalsIgnoreCase(pushRequestURI.getHost()))
-                    return;
-
-                int initiatingPort = initiatingURI.getPort();
-                if (initiatingPort == -1 ) {
-                    if ("https".equalsIgnoreCase(initiatingURI.getScheme()))
-                        initiatingPort = 443;
-                    else
-                        initiatingPort = 80;
-                }
-                int pushPort = pushRequestURI.getPort();
-                if (pushPort == -1 ) {
-                    if ("https".equalsIgnoreCase(pushRequestURI.getScheme()))
-                        pushPort = 443;
-                    else
-                        pushPort = 80;
-                }
-                if (initiatingPort != pushPort)
-                    return;
-
-                CompletableFuture<HttpResponse<T>> cf =
-                        acceptor.apply(pushPromiseHandler.apply(pushRequest));
-                pushPromisesMap.put(pushRequest, cf);
-            }
-        }
-
         /**
          * Returns a push promise handler that accumulates push promises, and
          * their responses, into the given map.