test/jdk/java/net/httpclient/http2/server/Http2TestServer.java
branchhttp-client-branch
changeset 55817 2aec8081d2ad
parent 47216 71c04702a3d5
child 55819 18e431209168
--- a/test/jdk/java/net/httpclient/http2/server/Http2TestServer.java	Wed Nov 15 11:39:54 2017 +0000
+++ b/test/jdk/java/net/httpclient/http2/server/Http2TestServer.java	Thu Nov 16 10:01:34 2017 +0000
@@ -131,6 +131,18 @@
         handlers.put(path, handler);
     }
 
+    volatile Http2TestExchangeSupplier exchangeSupplier = Http2TestExchangeSupplier.ofDefault();
+
+    /**
+     * Sets an explicit exchange handler to be used for all future connections.
+     * Useful for testing scenarios where non-standard or specific server
+     * behaviour is required, either direct control over the frames sent, "bad"
+     * behaviour, or something else.
+     */
+    public void setExchangeSupplier(Http2TestExchangeSupplier exchangeSupplier) {
+        this.exchangeSupplier = exchangeSupplier;
+    }
+
     Http2Handler getHandlerFor(String path) {
         if (path == null || path.equals(""))
             path = "/";
@@ -199,7 +211,8 @@
                 while (!stopping) {
                     Socket socket = server.accept();
                     InetSocketAddress addr = (InetSocketAddress) socket.getRemoteSocketAddress();
-                    Http2TestServerConnection c = new Http2TestServerConnection(this, socket);
+                    Http2TestServerConnection c =
+                            new Http2TestServerConnection(this, socket, exchangeSupplier);
                     connections.put(addr, c);
                     try {
                         c.run();