author | mbaesken |
Thu, 28 Nov 2019 13:02:39 +0100 | |
changeset 59323 | ae2eb76c486d |
parent 51364 | 31d9e82b2e64 |
child 56868 | 67c7659ecda5 |
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; |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
32 |
import java.util.function.Function; |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
33 |
import jdk.internal.net.http.common.MinimalFuture; |
49765 | 34 |
import jdk.internal.net.http.common.SSLTube; |
35 |
import jdk.internal.net.http.common.Utils; |
|
46157 | 36 |
|
37 |
/** |
|
38 |
* An SSL tunnel built on a Plain (CONNECT) TCP tunnel. |
|
39 |
*/ |
|
40 |
class AsyncSSLTunnelConnection extends AbstractAsyncSSLConnection { |
|
41 |
||
42 |
final PlainTunnelingConnection plainConnection; |
|
48083 | 43 |
final PlainHttpPublisher writePublisher; |
44 |
volatile SSLTube flow; |
|
46157 | 45 |
|
48083 | 46 |
AsyncSSLTunnelConnection(InetSocketAddress addr, |
47 |
HttpClientImpl client, |
|
48 |
String[] alpn, |
|
49765 | 49 |
InetSocketAddress proxy, |
50 |
HttpHeaders proxyHeaders) |
|
48083 | 51 |
{ |
49765 | 52 |
super(addr, client, Utils.getServerName(addr), addr.getPort(), alpn); |
53 |
this.plainConnection = new PlainTunnelingConnection(addr, proxy, client, proxyHeaders); |
|
48083 | 54 |
this.writePublisher = new PlainHttpPublisher(); |
46157 | 55 |
} |
56 |
||
57 |
@Override |
|
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
58 |
public CompletableFuture<Void> connectAsync(Exchange<?> exchange) { |
49765 | 59 |
if (debug.on()) debug.log("Connecting plain tunnel connection"); |
48083 | 60 |
// This will connect the PlainHttpConnection flow, so that |
61 |
// its HttpSubscriber and HttpPublisher are subscribed to the |
|
62 |
// SocketTube |
|
63 |
return plainConnection |
|
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
64 |
.connectAsync(exchange) |
48083 | 65 |
.thenApply( unused -> { |
49765 | 66 |
if (debug.on()) debug.log("creating SSLTube"); |
48083 | 67 |
// create the SSLTube wrapping the SocketTube, with the given engine |
68 |
flow = new SSLTube(engine, |
|
69 |
client().theExecutor(), |
|
49944 | 70 |
client().getSSLBufferSupplier()::recycle, |
48083 | 71 |
plainConnection.getConnectionFlow()); |
72 |
return null;} ); |
|
46157 | 73 |
} |
74 |
||
75 |
@Override |
|
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
76 |
public CompletableFuture<Void> finishConnect() { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
77 |
// The actual ALPN value, which may be the empty string, is not |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
78 |
// interesting at this point, only that the handshake has completed. |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
79 |
return getALPN() |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
80 |
.handle((String unused, Throwable ex) -> { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
81 |
if (ex == null) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
82 |
return plainConnection.finishConnect(); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
83 |
} else { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
84 |
plainConnection.close(); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
85 |
return MinimalFuture.<Void>failedFuture(ex); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
86 |
} }) |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
87 |
.thenCompose(Function.identity()); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
88 |
} |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
89 |
|
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
90 |
@Override |
49765 | 91 |
boolean isTunnel() { return true; } |
92 |
||
93 |
@Override |
|
48083 | 94 |
boolean connected() { |
95 |
return plainConnection.connected(); // && sslDelegate.connected(); |
|
46157 | 96 |
} |
97 |
||
98 |
@Override |
|
48083 | 99 |
HttpPublisher publisher() { return writePublisher; } |
46157 | 100 |
|
101 |
@Override |
|
102 |
public String toString() { |
|
103 |
return "AsyncSSLTunnelConnection: " + super.toString(); |
|
104 |
} |
|
105 |
||
106 |
@Override |
|
107 |
ConnectionPool.CacheKey cacheKey() { |
|
108 |
return ConnectionPool.cacheKey(address, plainConnection.proxyAddr); |
|
109 |
} |
|
110 |
||
111 |
@Override |
|
112 |
public void close() { |
|
48083 | 113 |
plainConnection.close(); |
46157 | 114 |
} |
115 |
||
116 |
@Override |
|
117 |
SocketChannel channel() { |
|
118 |
return plainConnection.channel(); |
|
119 |
} |
|
120 |
||
121 |
@Override |
|
122 |
boolean isProxied() { |
|
123 |
return true; |
|
124 |
} |
|
125 |
||
126 |
@Override |
|
48083 | 127 |
SSLTube getConnectionFlow() { |
128 |
return flow; |
|
129 |
} |
|
46157 | 130 |
} |