< prev index next >

src/java.net.http/share/classes/jdk/internal/net/http/HttpResponseImpl.java

Print this page
rev 53931 : Backport JDK-8236859

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2020, 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.  Oracle designates this

@@ -158,10 +158,30 @@
             rawchan = new RawChannelTube(connection, initial);
         }
         return rawchan;
     }
 
+    /**
+     * Closes the RawChannel that may have been used for WebSocket protocol.
+     *
+     * @apiNote This method should be called to close the connection
+     * if an exception occurs during the websocket handshake, in cases where
+     * {@link #rawChannel() rawChannel().close()} would have been called.
+     * An unsuccessful handshake may prevent the creation of the RawChannel:
+     * if a RawChannel has already been created, this method wil close it.
+     * Otherwise, it will close the connection.
+     *
+     * @throws IOException if an I/O exception occurs while closing
+     *         the channel.
+     */
+    public synchronized void closeRawChannel() throws IOException {
+            //  close the rawChannel, if created, or the
+            // connection, if not.
+            if (rawchan != null) rawchan.close();
+            else connection.close();
+        }
+
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();
         String method = request().method();
         URI uri = request().uri();
< prev index next >