author | prappo |
Mon, 13 Nov 2017 16:13:11 +0300 | |
branch | http-client-branch |
changeset 55805 | 371ed971281e |
parent 55803 | 259cf67b22ec |
child 55815 | 4f699653026b |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
4 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
10 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
15 |
* accompanied this code). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
16 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
20 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
23 |
* questions. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
24 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
26 |
package jdk.incubator.http; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
27 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
28 |
import java.io.IOException; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
29 |
import java.lang.System.Logger.Level; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
30 |
import java.net.InetSocketAddress; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
31 |
import java.net.ProxySelector; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
32 |
import java.net.URI; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
33 |
import java.net.URISyntaxException; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
34 |
import java.net.URLPermission; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
35 |
import java.security.AccessControlContext; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
36 |
import java.util.List; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
37 |
import java.util.Map; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
38 |
import java.util.concurrent.CompletableFuture; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
39 |
import java.util.concurrent.Executor; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
40 |
import jdk.incubator.http.internal.common.MinimalFuture; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
41 |
import jdk.incubator.http.internal.common.Utils; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
42 |
import jdk.incubator.http.internal.common.Log; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
43 |
|
55805 | 44 |
import static jdk.incubator.http.internal.common.Utils.permissionForProxy; |
45 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
46 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
47 |
* One request/response exchange (handles 100/101 intermediate response also). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
48 |
* depth field used to track number of times a new request is being sent |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
49 |
* for a given API request. If limit exceeded exception is thrown. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
50 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
51 |
* Security check is performed here: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
52 |
* - uses AccessControlContext captured at API level |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
53 |
* - checks for appropriate URLPermission for request |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
54 |
* - if permission allowed, grants equivalent SocketPermission to call |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
55 |
* - in case of direct HTTP proxy, checks additionally for access to proxy |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
56 |
* (CONNECT proxying uses its own Exchange, so check done there) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
57 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
58 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
59 |
final class Exchange<T> { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
60 |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
61 |
static final boolean DEBUG = Utils.DEBUG; // Revisit: temporary dev flag. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
62 |
final System.Logger debug = Utils.getDebugLogger(this::dbgString, DEBUG); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
63 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
64 |
final HttpRequestImpl request; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
65 |
final HttpClientImpl client; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
66 |
volatile ExchangeImpl<T> exchImpl; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
67 |
// used to record possible cancellation raised before the exchImpl |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
68 |
// has been established. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
69 |
private volatile IOException failed; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
70 |
final AccessControlContext acc; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
71 |
final MultiExchange<?,T> multi; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
72 |
final Executor parentExecutor; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
73 |
boolean upgrading; // to HTTP/2 |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
74 |
final PushGroup<?,T> pushGroup; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
75 |
final String dbgTag; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
76 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
77 |
Exchange(HttpRequestImpl request, MultiExchange<?,T> multi) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
78 |
this.request = request; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
79 |
this.upgrading = false; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
80 |
this.client = multi.client(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
81 |
this.multi = multi; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
82 |
this.acc = multi.acc; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
83 |
this.parentExecutor = multi.executor; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
84 |
this.pushGroup = multi.pushGroup; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
85 |
this.dbgTag = "Exchange"; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
86 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
87 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
88 |
/* If different AccessControlContext to be used */ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
89 |
Exchange(HttpRequestImpl request, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
90 |
MultiExchange<?,T> multi, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
91 |
AccessControlContext acc) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
92 |
{ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
93 |
this.request = request; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
94 |
this.acc = acc; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
95 |
this.upgrading = false; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
96 |
this.client = multi.client(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
97 |
this.multi = multi; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
98 |
this.parentExecutor = multi.executor; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
99 |
this.pushGroup = multi.pushGroup; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
100 |
this.dbgTag = "Exchange"; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
101 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
102 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
103 |
PushGroup<?,T> getPushGroup() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
104 |
return pushGroup; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
105 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
106 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
107 |
Executor executor() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
108 |
return parentExecutor; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
109 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
110 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
111 |
public HttpRequestImpl request() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
112 |
return request; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
113 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
114 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
115 |
HttpClientImpl client() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
116 |
return client; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
117 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
118 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
119 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
120 |
public CompletableFuture<T> readBodyAsync(HttpResponse.BodyHandler<T> handler) { |
43999
4cc44dd9f14f
8164625: Pooled HttpConnection should be removed during close
prappo
parents:
43984
diff
changeset
|
121 |
// The connection will not be returned to the pool in the case of WebSocket |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
122 |
return exchImpl.readBodyAsync(handler, !request.isWebSocket(), parentExecutor) |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
123 |
.whenComplete((r,t) -> exchImpl.completed()); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
124 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
125 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
126 |
/** |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
127 |
* Called when a new exchange is created to replace this exchange. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
128 |
* At this point it is guaranteed that readBody/readBodyAsync will |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
129 |
* not be called. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
130 |
*/ |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
131 |
public void released() { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
132 |
ExchangeImpl<?> impl = exchImpl; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
133 |
if (impl != null) impl.released(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
134 |
// Don't set exchImpl to null here. We need to keep |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
135 |
// it alive until it's replaced by a Stream in wrapForUpgrade. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
136 |
// Setting it to null here might get it GC'ed too early, because |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
137 |
// the Http1Response is now only weakly referenced by the Selector. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
138 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
139 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
140 |
public void cancel() { |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
141 |
// cancel can be called concurrently before or at the same time |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
142 |
// that the exchange impl is being established. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
143 |
// In that case we won't be able to propagate the cancellation |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
144 |
// right away |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
145 |
if (exchImpl != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
146 |
exchImpl.cancel(); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
147 |
} else { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
148 |
// no impl - can't cancel impl yet. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
149 |
// call cancel(IOException) instead which takes care |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
150 |
// of race conditions between impl/cancel. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
151 |
cancel(new IOException("Request cancelled")); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
152 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
153 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
154 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
155 |
public void cancel(IOException cause) { |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
156 |
// If the impl is non null, propagate the exception right away. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
157 |
// Otherwise record it so that it can be propagated once the |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
158 |
// exchange impl has been established. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
159 |
ExchangeImpl<?> impl = exchImpl; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
160 |
if (impl != null) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
161 |
// propagate the exception to the impl |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
162 |
debug.log(Level.DEBUG, "Cancelling exchImpl: %s", exchImpl); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
163 |
impl.cancel(cause); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
164 |
} else { |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
165 |
// no impl yet. record the exception |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
166 |
failed = cause; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
167 |
// now call checkCancelled to recheck the impl. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
168 |
// if the failed state is set and the impl is not null, reset |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
169 |
// the failed state and propagate the exception to the impl. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
170 |
checkCancelled(); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
171 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
172 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
173 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
174 |
// This method will raise an exception if one was reported and if |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
175 |
// it is possible to do so. If the exception can be raised, then |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
176 |
// the failed state will be reset. Otherwise, the failed state |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
177 |
// will persist until the exception can be raised and the failed state |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
178 |
// can be cleared. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
179 |
// Takes care of possible race conditions. |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
180 |
private void checkCancelled() { |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
181 |
ExchangeImpl<?> impl = null; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
182 |
IOException cause = null; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
183 |
if (failed != null) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
184 |
synchronized(this) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
185 |
cause = failed; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
186 |
impl = exchImpl; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
187 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
188 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
189 |
if (cause == null) return; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
190 |
if (impl != null) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
191 |
// The exception is raised by propagating it to the impl. |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
192 |
debug.log(Level.DEBUG, "Cancelling exchImpl: %s", impl); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
193 |
impl.cancel(cause); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
194 |
failed = null; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
195 |
} else { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
196 |
Log.logTrace("Exchange: request [{0}/timeout={1}ms] no impl is set." |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
197 |
+ "\n\tCan''t cancel yet with {2}", |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
198 |
request.uri(), |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
199 |
request.timeout().isPresent() ? |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
200 |
// calling duration.toMillis() can throw an exception. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
201 |
// this is just debugging, we don't care if it overflows. |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
202 |
(request.timeout().get().getSeconds() * 1000 |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
203 |
+ request.timeout().get().getNano() / 1000000) : -1, |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
204 |
cause); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
205 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
206 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
207 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
208 |
public void h2Upgrade() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
209 |
upgrading = true; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
210 |
request.setH2Upgrade(client.client2()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
211 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
212 |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
213 |
synchronized IOException getCancelCause() { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
214 |
return failed; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
215 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
216 |
|
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
217 |
// get/set the exchange impl, solving race condition issues with |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
218 |
// potential concurrent calls to cancel() or cancel(IOException) |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
219 |
private CompletableFuture<? extends ExchangeImpl<T>> |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
220 |
establishExchange(HttpConnection connection) { |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
221 |
// check if we have been cancelled first. |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
222 |
Throwable t = getCancelCause(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
223 |
checkCancelled(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
224 |
if (t != null) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
225 |
return MinimalFuture.failedFuture(t); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
226 |
} |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
227 |
CompletableFuture<? extends ExchangeImpl<T>> cf = ExchangeImpl.get(this, connection); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
228 |
return cf.thenCompose((eimpl) -> { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
229 |
// recheck for cancelled, in case of race conditions |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
230 |
exchImpl = eimpl; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
231 |
IOException tt = getCancelCause(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
232 |
checkCancelled(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
233 |
if (tt != null) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
234 |
return MinimalFuture.failedFuture(tt); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
235 |
} else { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
236 |
// Now we're good to go. Because exchImpl is no longer |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
237 |
// null cancel() will be able to propagate directly to |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
238 |
// the impl after this point ( if needed ). |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
239 |
return MinimalFuture.completedFuture(eimpl); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
240 |
} }); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
241 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
242 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
243 |
// Completed HttpResponse will be null if response succeeded |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
244 |
// will be a non null responseAsync if expect continue returns an error |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
245 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
246 |
public CompletableFuture<Response> responseAsync() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
247 |
return responseAsyncImpl(null); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
248 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
249 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
250 |
CompletableFuture<Response> responseAsyncImpl(HttpConnection connection) { |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
251 |
SecurityException e = checkPermissions(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
252 |
if (e != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
253 |
return MinimalFuture.failedFuture(e); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
254 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
255 |
return responseAsyncImpl0(connection); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
256 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
257 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
258 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
259 |
CompletableFuture<Response> responseAsyncImpl0(HttpConnection connection) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
260 |
if (request.expectContinue()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
261 |
request.addSystemHeader("Expect", "100-Continue"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
262 |
Log.logTrace("Sending Expect: 100-Continue"); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
263 |
return establishExchange(connection) |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
264 |
.thenCompose((ex) -> ex.sendHeadersAsync()) |
43984 | 265 |
.thenCompose(v -> exchImpl.getResponseAsync(parentExecutor)) |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
266 |
.thenCompose((Response r1) -> { |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
267 |
Log.logResponse(r1::toString); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
268 |
int rcode = r1.statusCode(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
269 |
if (rcode == 100) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
270 |
Log.logTrace("Received 100-Continue: sending body"); |
43984 | 271 |
CompletableFuture<Response> cf = |
272 |
exchImpl.sendBodyAsync() |
|
273 |
.thenCompose(exIm -> exIm.getResponseAsync(parentExecutor)); |
|
274 |
cf = wrapForUpgrade(cf); |
|
275 |
cf = wrapForLog(cf); |
|
276 |
return cf; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
277 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
278 |
Log.logTrace("Expectation failed: Received {0}", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
279 |
rcode); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
280 |
if (upgrading && rcode == 101) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
281 |
IOException failed = new IOException( |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
282 |
"Unable to handle 101 while waiting for 100"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
283 |
return MinimalFuture.failedFuture(failed); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
284 |
} |
43984 | 285 |
return exchImpl.readBodyAsync(this::ignoreBody, false, parentExecutor) |
286 |
.thenApply(v -> r1); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
287 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
288 |
}); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
289 |
} else { |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
290 |
CompletableFuture<Response> cf = establishExchange(connection) |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
291 |
.thenCompose((ex) -> ex.sendHeadersAsync()) |
43984 | 292 |
.thenCompose(ExchangeImpl::sendBodyAsync) |
293 |
.thenCompose(exIm -> exIm.getResponseAsync(parentExecutor)); |
|
294 |
cf = wrapForUpgrade(cf); |
|
295 |
cf = wrapForLog(cf); |
|
296 |
return cf; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
297 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
298 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
299 |
|
43984 | 300 |
private CompletableFuture<Response> wrapForUpgrade(CompletableFuture<Response> cf) { |
301 |
if (upgrading) { |
|
302 |
return cf.thenCompose(r -> checkForUpgradeAsync(r, exchImpl)); |
|
303 |
} |
|
304 |
return cf; |
|
305 |
} |
|
306 |
||
307 |
private CompletableFuture<Response> wrapForLog(CompletableFuture<Response> cf) { |
|
308 |
if (Log.requests()) { |
|
309 |
return cf.thenApply(response -> { |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
310 |
Log.logResponse(response::toString); |
43984 | 311 |
return response; |
312 |
}); |
|
313 |
} |
|
314 |
return cf; |
|
315 |
} |
|
316 |
||
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
317 |
HttpResponse.BodySubscriber<T> ignoreBody(int status, HttpHeaders hdrs) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
318 |
return HttpResponse.BodySubscriber.discard((T)null); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
319 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
320 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
321 |
// if this response was received in reply to an upgrade |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
322 |
// then create the Http2Connection from the HttpConnection |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
323 |
// initialize it and wait for the real response on a newly created Stream |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
324 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
325 |
private CompletableFuture<Response> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
326 |
checkForUpgradeAsync(Response resp, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
327 |
ExchangeImpl<T> ex) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
328 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
329 |
int rcode = resp.statusCode(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
330 |
if (upgrading && (rcode == 101)) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
331 |
Http1Exchange<T> e = (Http1Exchange<T>)ex; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
332 |
// check for 101 switching protocols |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
333 |
// 101 responses are not supposed to contain a body. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
334 |
// => should we fail if there is one? |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
335 |
debug.log(Level.DEBUG, "Upgrading async %s" + e.connection()); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
336 |
return e.readBodyAsync(this::ignoreBody, false, parentExecutor) |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
337 |
.thenCompose((T v) -> {// v is null |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
338 |
debug.log(Level.DEBUG, "Ignored body"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
339 |
// we pass e::getBuffer to allow the ByteBuffers to accumulate |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
340 |
// while we build the Http2Connection |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
341 |
return Http2Connection.createAsync(e.connection(), |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
342 |
client.client2(), |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
343 |
this, e::getBuffer) |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
344 |
.thenCompose((Http2Connection c) -> { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
345 |
c.putConnection(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
346 |
Stream<T> s = c.getStream(1); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
347 |
if (s == null) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
348 |
// s can be null if an exception occurred |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
349 |
// asynchronously while sending the preface. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
350 |
Throwable t = c.getRecordedCause(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
351 |
if (t != null) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
352 |
return MinimalFuture.failedFuture( |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
353 |
new IOException("Can't get stream 1: " + t, t)); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
354 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
355 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
356 |
exchImpl.released(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
357 |
Throwable t; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
358 |
// There's a race condition window where an external |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
359 |
// thread (SelectorManager) might complete the |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
360 |
// exchange in timeout at the same time where we're |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
361 |
// trying to switch the exchange impl. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
362 |
// 'failed' will be reset to null after |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
363 |
// exchImpl.cancel() has completed, so either we |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
364 |
// will observe failed != null here, or we will |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
365 |
// observe e.getCancelCause() != null, or the |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
366 |
// timeout exception will be routed to 's'. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
367 |
// Either way, we need to relay it to s. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
368 |
synchronized (this) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
369 |
exchImpl = s; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
370 |
t = failed; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
371 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
372 |
// Check whether the HTTP/1.1 was cancelled. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
373 |
if (t == null) t = e.getCancelCause(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
374 |
// if HTTP/1.1 exchange was timed out, don't |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
375 |
// try to go further. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
376 |
if (t instanceof HttpTimeoutException) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
377 |
s.cancelImpl(t); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
378 |
return MinimalFuture.failedFuture(t); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
379 |
} |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
380 |
debug.log(Level.DEBUG, "Getting response async %s" + s); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
381 |
return s.getResponseAsync(null); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
382 |
});} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
383 |
); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
384 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
385 |
return MinimalFuture.completedFuture(resp); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
386 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
387 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
388 |
private URI getURIForSecurityCheck() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
389 |
URI u; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
390 |
String method = request.method(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
391 |
InetSocketAddress authority = request.authority(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
392 |
URI uri = request.uri(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
393 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
394 |
// CONNECT should be restricted at API level |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
395 |
if (method.equalsIgnoreCase("CONNECT")) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
396 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
397 |
u = new URI("socket", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
398 |
null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
399 |
authority.getHostString(), |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
400 |
authority.getPort(), |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
401 |
null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
402 |
null, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
403 |
null); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
404 |
} catch (URISyntaxException e) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
405 |
throw new InternalError(e); // shouldn't happen |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
406 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
407 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
408 |
u = uri; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
409 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
410 |
return u; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
411 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
412 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
413 |
/** |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
414 |
* Returns the security permission required for the given details. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
415 |
* If method is CONNECT, then uri must be of form "scheme://host:port" |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
416 |
*/ |
55764
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
417 |
private static URLPermission permissionForServer(URI uri, |
55805 | 418 |
String method, |
419 |
Map<String, List<String>> headers) { |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
420 |
if (method.equals("CONNECT")) { |
55805 | 421 |
return new URLPermission(uri.toString(), "CONNECT"); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
422 |
} else { |
55805 | 423 |
return Utils.permissionForServer(uri, method, headers.keySet().stream()); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
424 |
} |
55764
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
425 |
} |
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
426 |
|
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
427 |
/** |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
428 |
* Performs the necessary security permission checks required to retrieve |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
429 |
* the response. Returns a security exception representing the denied |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
430 |
* permission, or null if all checks pass or there is no security manager. |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
431 |
*/ |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
432 |
private SecurityException checkPermissions() { |
55764
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
433 |
String method = request.method(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
434 |
SecurityManager sm = System.getSecurityManager(); |
55764
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
435 |
if (sm == null || method.equals("CONNECT")) { |
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
436 |
// tunneling will have a null acc, which is fine. The proxy |
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
437 |
// permission check will have already been preformed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
438 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
439 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
440 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
441 |
HttpHeaders userHeaders = request.getUserHeaders(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
442 |
URI u = getURIForSecurityCheck(); |
55764
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
443 |
URLPermission p = permissionForServer(u, method, userHeaders.map()); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
444 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
445 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
446 |
assert acc != null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
447 |
sm.checkPermission(p, acc); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
448 |
} catch (SecurityException e) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
449 |
return e; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
450 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
451 |
ProxySelector ps = client.proxy().orElse(null); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
452 |
if (ps != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
453 |
if (!method.equals("CONNECT")) { |
55764
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
454 |
// a non-tunneling HTTP proxy. Need to check access |
55805 | 455 |
URLPermission proxyPerm = permissionForProxy(request.proxy()); |
55764
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
456 |
if (proxyPerm != null) { |
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
457 |
try { |
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
458 |
sm.checkPermission(proxyPerm, acc); |
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
459 |
} catch (SecurityException e) { |
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
460 |
return e; |
34d7cc00f87a
http-client-branch: WebSocket permission checks, test updates, and more
chegar
parents:
55763
diff
changeset
|
461 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
462 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
463 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
464 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
465 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
466 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
467 |
|
55792
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
468 |
// HttpClient.Redirect followRedirects() { |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
469 |
// return client.followRedirects(); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
470 |
// } |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
471 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
472 |
HttpClient.Version version() { |
44854
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
44639
diff
changeset
|
473 |
return multi.version(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
474 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
475 |
|
55792
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
476 |
// private static SocketPermission getSocketPermissionFor(URI url) { |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
477 |
// if (System.getSecurityManager() == null) { |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
478 |
// return null; |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
479 |
// } |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
480 |
// |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
481 |
// StringBuilder sb = new StringBuilder(); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
482 |
// String host = url.getHost(); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
483 |
// sb.append(host); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
484 |
// int port = url.getPort(); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
485 |
// if (port == -1) { |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
486 |
// String scheme = url.getScheme(); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
487 |
// if ("http".equals(scheme)) { |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
488 |
// sb.append(":80"); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
489 |
// } else { // scheme must be https |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
490 |
// sb.append(":443"); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
491 |
// } |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
492 |
// } else { |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
493 |
// sb.append(':') |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
494 |
// .append(Integer.toString(port)); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
495 |
// } |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
496 |
// String target = sb.toString(); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
497 |
// return new SocketPermission(target, "connect"); |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
498 |
// } |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
499 |
|
55792
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
500 |
// AccessControlContext getAccessControlContext() { |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
501 |
// return acc; |
0936888d5a4a
http-client-branch: (cleanup) unused imports, unused methods, removed 1 class; typos;
prappo
parents:
55764
diff
changeset
|
502 |
// } |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
503 |
|
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
504 |
String dbgString() { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
505 |
return dbgTag; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
506 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
507 |
} |