author | michaelm |
Wed, 14 Feb 2018 16:04:18 +0000 | |
branch | http-client-branch |
changeset 56126 | 86e628130926 |
parent 56092 | fd85b2bf2b0d |
child 56335 | 7e56c39fa1fa |
permissions | -rw-r--r-- |
46157 | 1 |
/* |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
55973
diff
changeset
|
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 |
||
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
26 |
package jdk.internal.net.http; |
46157 | 27 |
|
28 |
import java.io.IOException; |
|
48083 | 29 |
import java.lang.System.Logger.Level; |
46157 | 30 |
import java.net.InetSocketAddress; |
31 |
import java.nio.channels.SocketChannel; |
|
32 |
import java.util.concurrent.CompletableFuture; |
|
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56079
diff
changeset
|
33 |
import java.net.http.HttpHeaders; |
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
34 |
import jdk.internal.net.http.common.SSLTube; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
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, |
|
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
55973
diff
changeset
|
49 |
InetSocketAddress proxy, |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
55973
diff
changeset
|
50 |
HttpHeaders proxyHeaders) |
48083 | 51 |
{ |
56126
86e628130926
http-client-branch: fixed TLS hostname checking issue, SSL session reuse, and changed HttpResponse to return SSLSession
michaelm
parents:
56092
diff
changeset
|
52 |
super(addr, client, Utils.getServerName(addr), addr.getPort(), alpn); |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
55973
diff
changeset
|
53 |
this.plainConnection = new PlainTunnelingConnection(addr, proxy, client, proxyHeaders); |
48083 | 54 |
this.writePublisher = new PlainHttpPublisher(); |
46157 | 55 |
} |
56 |
||
57 |
@Override |
|
58 |
public CompletableFuture<Void> connectAsync() { |
|
48083 | 59 |
debug.log(Level.DEBUG, "Connecting plain tunnel connection"); |
60 |
// This will connect the PlainHttpConnection flow, so that |
|
61 |
// its HttpSubscriber and HttpPublisher are subscribed to the |
|
62 |
// SocketTube |
|
63 |
return plainConnection |
|
64 |
.connectAsync() |
|
65 |
.thenApply( unused -> { |
|
66 |
debug.log(Level.DEBUG, "creating SSLTube"); |
|
67 |
// create the SSLTube wrapping the SocketTube, with the given engine |
|
68 |
flow = new SSLTube(engine, |
|
69 |
client().theExecutor(), |
|
70 |
plainConnection.getConnectionFlow()); |
|
71 |
return null;} ); |
|
46157 | 72 |
} |
73 |
||
74 |
@Override |
|
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
55973
diff
changeset
|
75 |
boolean isTunnel() { return true; } |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
55973
diff
changeset
|
76 |
|
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
55973
diff
changeset
|
77 |
@Override |
48083 | 78 |
boolean connected() { |
79 |
return plainConnection.connected(); // && sslDelegate.connected(); |
|
46157 | 80 |
} |
81 |
||
82 |
@Override |
|
48083 | 83 |
HttpPublisher publisher() { return writePublisher; } |
46157 | 84 |
|
85 |
@Override |
|
86 |
public String toString() { |
|
87 |
return "AsyncSSLTunnelConnection: " + super.toString(); |
|
88 |
} |
|
89 |
||
90 |
@Override |
|
91 |
PlainTunnelingConnection plainConnection() { |
|
92 |
return plainConnection; |
|
93 |
} |
|
94 |
||
95 |
@Override |
|
96 |
ConnectionPool.CacheKey cacheKey() { |
|
97 |
return ConnectionPool.cacheKey(address, plainConnection.proxyAddr); |
|
98 |
} |
|
99 |
||
100 |
@Override |
|
101 |
public void close() { |
|
48083 | 102 |
plainConnection.close(); |
46157 | 103 |
} |
104 |
||
105 |
@Override |
|
106 |
void shutdownInput() throws IOException { |
|
107 |
plainConnection.channel().shutdownInput(); |
|
108 |
} |
|
109 |
||
110 |
@Override |
|
111 |
void shutdownOutput() throws IOException { |
|
112 |
plainConnection.channel().shutdownOutput(); |
|
113 |
} |
|
114 |
||
115 |
@Override |
|
116 |
SocketChannel channel() { |
|
117 |
return plainConnection.channel(); |
|
118 |
} |
|
119 |
||
120 |
@Override |
|
121 |
boolean isProxied() { |
|
122 |
return true; |
|
123 |
} |
|
124 |
||
125 |
@Override |
|
48083 | 126 |
SSLTube getConnectionFlow() { |
127 |
return flow; |
|
128 |
} |
|
46157 | 129 |
} |