author | dfuchs |
Mon, 23 Apr 2018 15:45:40 +0100 | |
branch | http-client-branch |
changeset 56474 | fe2bf7b369b8 |
parent 56451 | 9585061fdb04 |
child 56507 | 2294c51eae30 |
permissions | -rw-r--r-- |
46157 | 1 |
/* |
49765 | 2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
46157 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
49765 | 26 |
package jdk.internal.net.http; |
46157 | 27 |
|
28 |
import java.net.InetSocketAddress; |
|
29 |
import java.nio.channels.SocketChannel; |
|
30 |
import java.util.concurrent.CompletableFuture; |
|
49765 | 31 |
import java.net.http.HttpHeaders; |
32 |
import jdk.internal.net.http.common.SSLTube; |
|
33 |
import jdk.internal.net.http.common.Utils; |
|
46157 | 34 |
|
35 |
/** |
|
36 |
* An SSL tunnel built on a Plain (CONNECT) TCP tunnel. |
|
37 |
*/ |
|
38 |
class AsyncSSLTunnelConnection extends AbstractAsyncSSLConnection { |
|
39 |
||
40 |
final PlainTunnelingConnection plainConnection; |
|
48083 | 41 |
final PlainHttpPublisher writePublisher; |
42 |
volatile SSLTube flow; |
|
46157 | 43 |
|
48083 | 44 |
AsyncSSLTunnelConnection(InetSocketAddress addr, |
45 |
HttpClientImpl client, |
|
46 |
String[] alpn, |
|
49765 | 47 |
InetSocketAddress proxy, |
48 |
HttpHeaders proxyHeaders) |
|
48083 | 49 |
{ |
49765 | 50 |
super(addr, client, Utils.getServerName(addr), addr.getPort(), alpn); |
51 |
this.plainConnection = new PlainTunnelingConnection(addr, proxy, client, proxyHeaders); |
|
48083 | 52 |
this.writePublisher = new PlainHttpPublisher(); |
46157 | 53 |
} |
54 |
||
55 |
@Override |
|
56 |
public CompletableFuture<Void> connectAsync() { |
|
49765 | 57 |
if (debug.on()) debug.log("Connecting plain tunnel connection"); |
48083 | 58 |
// This will connect the PlainHttpConnection flow, so that |
59 |
// its HttpSubscriber and HttpPublisher are subscribed to the |
|
60 |
// SocketTube |
|
61 |
return plainConnection |
|
62 |
.connectAsync() |
|
63 |
.thenApply( unused -> { |
|
49765 | 64 |
if (debug.on()) debug.log("creating SSLTube"); |
48083 | 65 |
// create the SSLTube wrapping the SocketTube, with the given engine |
66 |
flow = new SSLTube(engine, |
|
67 |
client().theExecutor(), |
|
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
68 |
client().getSSLBufferSupplier()::recycle, |
48083 | 69 |
plainConnection.getConnectionFlow()); |
70 |
return null;} ); |
|
46157 | 71 |
} |
72 |
||
73 |
@Override |
|
49765 | 74 |
boolean isTunnel() { return true; } |
75 |
||
76 |
@Override |
|
48083 | 77 |
boolean connected() { |
78 |
return plainConnection.connected(); // && sslDelegate.connected(); |
|
46157 | 79 |
} |
80 |
||
81 |
@Override |
|
48083 | 82 |
HttpPublisher publisher() { return writePublisher; } |
46157 | 83 |
|
84 |
@Override |
|
85 |
public String toString() { |
|
86 |
return "AsyncSSLTunnelConnection: " + super.toString(); |
|
87 |
} |
|
88 |
||
89 |
@Override |
|
90 |
PlainTunnelingConnection plainConnection() { |
|
91 |
return plainConnection; |
|
92 |
} |
|
93 |
||
94 |
@Override |
|
95 |
ConnectionPool.CacheKey cacheKey() { |
|
96 |
return ConnectionPool.cacheKey(address, plainConnection.proxyAddr); |
|
97 |
} |
|
98 |
||
99 |
@Override |
|
100 |
public void close() { |
|
48083 | 101 |
plainConnection.close(); |
46157 | 102 |
} |
103 |
||
104 |
@Override |
|
105 |
SocketChannel channel() { |
|
106 |
return plainConnection.channel(); |
|
107 |
} |
|
108 |
||
109 |
@Override |
|
110 |
boolean isProxied() { |
|
111 |
return true; |
|
112 |
} |
|
113 |
||
114 |
@Override |
|
48083 | 115 |
SSLTube getConnectionFlow() { |
116 |
return flow; |
|
117 |
} |
|
46157 | 118 |
} |