author | mbaesken |
Thu, 28 Nov 2019 13:02:39 +0100 | |
changeset 59323 | ae2eb76c486d |
parent 53699 | e402ec38ba9a |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
53467
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
52554
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, 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 |
|
49765 | 26 |
package jdk.internal.net.http; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
27 |
|
50681 | 28 |
import java.io.EOFException; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
29 |
import java.io.IOException; |
49765 | 30 |
import java.io.UncheckedIOException; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
31 |
import java.net.URI; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
32 |
import java.nio.ByteBuffer; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
33 |
import java.util.ArrayList; |
48083 | 34 |
import java.util.Collections; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
35 |
import java.util.List; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
36 |
import java.util.concurrent.CompletableFuture; |
48083 | 37 |
import java.util.concurrent.ConcurrentLinkedDeque; |
38 |
import java.util.concurrent.ConcurrentLinkedQueue; |
|
42460
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 java.util.concurrent.Flow; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
41 |
import java.util.concurrent.Flow.Subscription; |
50681 | 42 |
import java.util.concurrent.atomic.AtomicBoolean; |
48083 | 43 |
import java.util.concurrent.atomic.AtomicReference; |
49765 | 44 |
import java.util.function.BiPredicate; |
45 |
import java.net.http.HttpClient; |
|
46 |
import java.net.http.HttpHeaders; |
|
47 |
import java.net.http.HttpRequest; |
|
48 |
import java.net.http.HttpResponse; |
|
49 |
import java.net.http.HttpResponse.BodySubscriber; |
|
50 |
import jdk.internal.net.http.common.*; |
|
51 |
import jdk.internal.net.http.frame.*; |
|
52 |
import jdk.internal.net.http.hpack.DecodingCallback; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
53 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
54 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
55 |
* Http/2 Stream handling. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
56 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
57 |
* REQUESTS |
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 |
* sendHeadersOnly() -- assembles HEADERS frame and puts on connection outbound Q |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
60 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
61 |
* sendRequest() -- sendHeadersOnly() + sendBody() |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
62 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
63 |
* sendBodyAsync() -- calls sendBody() in an executor thread. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
64 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
65 |
* sendHeadersAsync() -- calls sendHeadersOnly() which does not block |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
66 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
67 |
* sendRequestAsync() -- calls sendRequest() in an executor thread |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
68 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
69 |
* RESPONSES |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
70 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
71 |
* Multiple responses can be received per request. Responses are queued up on |
52499
768b1c612100
8213490: Networking area typos and inconsistencies cleanup
prappo
parents:
50985
diff
changeset
|
72 |
* a LinkedList of CF<HttpResponse> and the first one on the list is completed |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
73 |
* with the next response |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
74 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
75 |
* getResponseAsync() -- queries list of response CFs and returns first one |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
76 |
* if one exists. Otherwise, creates one and adds it to list |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
77 |
* and returns it. Completion is achieved through the |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
78 |
* incoming() upcall from connection reader thread. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
79 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
80 |
* getResponse() -- calls getResponseAsync() and waits for CF to complete |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
81 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
82 |
* responseBodyAsync() -- calls responseBody() in an executor thread. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
83 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
84 |
* incoming() -- entry point called from connection reader thread. Frames are |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
85 |
* either handled immediately without blocking or for data frames |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
86 |
* placed on the stream's inputQ which is consumed by the stream's |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
87 |
* reader thread. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
88 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
89 |
* PushedStream sub class |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
90 |
* ====================== |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
91 |
* Sending side methods are not used because the request comes from a PUSH_PROMISE |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
92 |
* frame sent by the server. When a PUSH_PROMISE is received the PushedStream |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
93 |
* is created. PushedStream does not use responseCF list as there can be only |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
94 |
* one response. The CF is created when the object created and when the response |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
95 |
* HEADERS frame is received the object is completed. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
96 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
97 |
class Stream<T> extends ExchangeImpl<T> { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
98 |
|
49765 | 99 |
final Logger debug = Utils.getDebugLogger(this::dbgString, Utils.DEBUG); |
48083 | 100 |
|
101 |
final ConcurrentLinkedQueue<Http2Frame> inputQ = new ConcurrentLinkedQueue<>(); |
|
102 |
final SequentialScheduler sched = |
|
103 |
SequentialScheduler.synchronizedScheduler(this::schedule); |
|
49765 | 104 |
final SubscriptionBase userSubscription = |
105 |
new SubscriptionBase(sched, this::cancel, this::onSubscriptionError); |
|
42460
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 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
108 |
* This stream's identifier. Assigned lazily by the HTTP2Connection before |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
109 |
* the stream's first frame is sent. |
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 |
protected volatile int streamid; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
112 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
113 |
long requestContentLen; |
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 |
final Http2Connection connection; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
116 |
final HttpRequestImpl request; |
49765 | 117 |
final HeadersConsumer rspHeadersConsumer; |
50681 | 118 |
final HttpHeadersBuilder responseHeadersBuilder; |
119 |
final HttpHeaders requestPseudoHeaders; |
|
48083 | 120 |
volatile HttpResponse.BodySubscriber<T> responseSubscriber; |
121 |
final HttpRequest.BodyPublisher requestPublisher; |
|
122 |
volatile RequestSubscriber requestSubscriber; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
123 |
volatile int responseCode; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
124 |
volatile Response response; |
49765 | 125 |
// The exception with which this stream was canceled. |
126 |
private final AtomicReference<Throwable> errorRef = new AtomicReference<>(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
127 |
final CompletableFuture<Void> requestBodyCF = new MinimalFuture<>(); |
48083 | 128 |
volatile CompletableFuture<T> responseBodyCF; |
49765 | 129 |
volatile HttpResponse.BodySubscriber<T> pendingResponseSubscriber; |
130 |
volatile boolean stopRequested; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
131 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
132 |
/** True if END_STREAM has been seen in a frame received on this stream. */ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
133 |
private volatile boolean remotelyClosed; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
134 |
private volatile boolean closed; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
135 |
private volatile boolean endStreamSent; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
136 |
|
50681 | 137 |
final AtomicBoolean deRegistered = new AtomicBoolean(false); |
138 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
139 |
// state flags |
48083 | 140 |
private boolean requestSent, responseReceived; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
141 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
142 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
143 |
* A reference to this Stream's connection Send Window controller. The |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
144 |
* stream MUST acquire the appropriate amount of Send Window before |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
145 |
* sending any data. Will be null for PushStreams, as they cannot send data. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
146 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
147 |
private final WindowController windowController; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
148 |
private final WindowUpdateSender windowUpdater; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
149 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
150 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
151 |
HttpConnection connection() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
152 |
return connection.connection; |
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 |
|
48083 | 155 |
/** |
156 |
* Invoked either from incoming() -> {receiveDataFrame() or receiveResetFrame() } |
|
157 |
* of after user subscription window has re-opened, from SubscriptionBase.request() |
|
158 |
*/ |
|
159 |
private void schedule() { |
|
49765 | 160 |
boolean onCompleteCalled = false; |
161 |
HttpResponse.BodySubscriber<T> subscriber = responseSubscriber; |
|
162 |
try { |
|
163 |
if (subscriber == null) { |
|
164 |
subscriber = responseSubscriber = pendingResponseSubscriber; |
|
165 |
if (subscriber == null) { |
|
166 |
// can't process anything yet |
|
167 |
return; |
|
168 |
} else { |
|
169 |
if (debug.on()) debug.log("subscribing user subscriber"); |
|
170 |
subscriber.onSubscribe(userSubscription); |
|
171 |
} |
|
48083 | 172 |
} |
49765 | 173 |
while (!inputQ.isEmpty()) { |
174 |
Http2Frame frame = inputQ.peek(); |
|
175 |
if (frame instanceof ResetFrame) { |
|
176 |
inputQ.remove(); |
|
50681 | 177 |
handleReset((ResetFrame)frame, subscriber); |
49765 | 178 |
return; |
179 |
} |
|
180 |
DataFrame df = (DataFrame)frame; |
|
181 |
boolean finished = df.getFlag(DataFrame.END_STREAM); |
|
48083 | 182 |
|
49765 | 183 |
List<ByteBuffer> buffers = df.getData(); |
184 |
List<ByteBuffer> dsts = Collections.unmodifiableList(buffers); |
|
185 |
int size = Utils.remaining(dsts, Integer.MAX_VALUE); |
|
186 |
if (size == 0 && finished) { |
|
187 |
inputQ.remove(); |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
188 |
connection.ensureWindowUpdated(df); // must update connection window |
48083 | 189 |
Log.logTrace("responseSubscriber.onComplete"); |
49765 | 190 |
if (debug.on()) debug.log("incoming: onComplete"); |
48083 | 191 |
sched.stop(); |
50681 | 192 |
connection.decrementStreamsCount(streamid); |
49765 | 193 |
subscriber.onComplete(); |
194 |
onCompleteCalled = true; |
|
48083 | 195 |
setEndStreamReceived(); |
196 |
return; |
|
49765 | 197 |
} else if (userSubscription.tryDecrement()) { |
198 |
inputQ.remove(); |
|
199 |
Log.logTrace("responseSubscriber.onNext {0}", size); |
|
200 |
if (debug.on()) debug.log("incoming: onNext(%d)", size); |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
201 |
try { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
202 |
subscriber.onNext(dsts); |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
203 |
} catch (Throwable t) { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
204 |
connection.dropDataFrame(df); // must update connection window |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
205 |
throw t; |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
206 |
} |
49765 | 207 |
if (consumed(df)) { |
208 |
Log.logTrace("responseSubscriber.onComplete"); |
|
209 |
if (debug.on()) debug.log("incoming: onComplete"); |
|
210 |
sched.stop(); |
|
50681 | 211 |
connection.decrementStreamsCount(streamid); |
49765 | 212 |
subscriber.onComplete(); |
213 |
onCompleteCalled = true; |
|
214 |
setEndStreamReceived(); |
|
215 |
return; |
|
216 |
} |
|
217 |
} else { |
|
218 |
if (stopRequested) break; |
|
219 |
return; |
|
48083 | 220 |
} |
221 |
} |
|
49765 | 222 |
} catch (Throwable throwable) { |
223 |
errorRef.compareAndSet(null, throwable); |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
224 |
} finally { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
225 |
if (sched.isStopped()) drainInputQueue(); |
48083 | 226 |
} |
49765 | 227 |
|
228 |
Throwable t = errorRef.get(); |
|
48083 | 229 |
if (t != null) { |
230 |
sched.stop(); |
|
49765 | 231 |
try { |
232 |
if (!onCompleteCalled) { |
|
233 |
if (debug.on()) |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
234 |
debug.log("calling subscriber.onError: %s", (Object) t); |
49765 | 235 |
subscriber.onError(t); |
236 |
} else { |
|
237 |
if (debug.on()) |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
238 |
debug.log("already completed: dropping error %s", (Object) t); |
49765 | 239 |
} |
240 |
} catch (Throwable x) { |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
241 |
Log.logError("Subscriber::onError threw exception: {0}", (Object) t); |
49765 | 242 |
} finally { |
243 |
cancelImpl(t); |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
244 |
drainInputQueue(); |
49765 | 245 |
} |
48083 | 246 |
} |
247 |
} |
|
248 |
||
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
249 |
// must only be called from the scheduler schedule() loop. |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
250 |
// ensure that all received data frames are accounted for |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
251 |
// in the connection window flow control if the scheduler |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
252 |
// is stopped before all the data is consumed. |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
253 |
private void drainInputQueue() { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
254 |
Http2Frame frame; |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
255 |
while ((frame = inputQ.poll()) != null) { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
256 |
if (frame instanceof DataFrame) { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
257 |
connection.dropDataFrame((DataFrame)frame); |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
258 |
} |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
259 |
} |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
260 |
} |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
261 |
|
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
262 |
|
48083 | 263 |
// Callback invoked after the Response BodySubscriber has consumed the |
264 |
// buffers contained in a DataFrame. |
|
265 |
// Returns true if END_STREAM is reached, false otherwise. |
|
266 |
private boolean consumed(DataFrame df) { |
|
267 |
// RFC 7540 6.1: |
|
268 |
// The entire DATA frame payload is included in flow control, |
|
269 |
// including the Pad Length and Padding fields if present |
|
270 |
int len = df.payloadLength(); |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
271 |
boolean endStream = df.getFlag(DataFrame.END_STREAM); |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
272 |
if (len == 0) return endStream; |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
273 |
|
48083 | 274 |
connection.windowUpdater.update(len); |
275 |
||
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
276 |
if (!endStream) { |
48083 | 277 |
// Don't send window update on a stream which is |
278 |
// closed or half closed. |
|
279 |
windowUpdater.update(len); |
|
280 |
} |
|
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
281 |
|
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
282 |
// true: end of stream; false: more data coming |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
283 |
return endStream; |
48083 | 284 |
} |
285 |
||
50681 | 286 |
boolean deRegister() { |
287 |
return deRegistered.compareAndSet(false, true); |
|
288 |
} |
|
289 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
290 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
291 |
CompletableFuture<T> readBodyAsync(HttpResponse.BodyHandler<T> handler, |
43999
4cc44dd9f14f
8164625: Pooled HttpConnection should be removed during close
prappo
parents:
43984
diff
changeset
|
292 |
boolean returnConnectionToPool, |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
293 |
Executor executor) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
294 |
{ |
49765 | 295 |
try { |
296 |
Log.logTrace("Reading body on stream {0}", streamid); |
|
50681 | 297 |
debug.log("Getting BodySubscriber for: " + response); |
49765 | 298 |
BodySubscriber<T> bodySubscriber = handler.apply(new ResponseInfoImpl(response)); |
299 |
CompletableFuture<T> cf = receiveData(bodySubscriber, executor); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
300 |
|
49765 | 301 |
PushGroup<?> pg = exchange.getPushGroup(); |
302 |
if (pg != null) { |
|
303 |
// if an error occurs make sure it is recorded in the PushGroup |
|
304 |
cf = cf.whenComplete((t, e) -> pg.pushError(e)); |
|
305 |
} |
|
306 |
return cf; |
|
307 |
} catch (Throwable t) { |
|
308 |
// may be thrown by handler.apply |
|
309 |
cancelImpl(t); |
|
310 |
return MinimalFuture.failedFuture(t); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
311 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
312 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
313 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
314 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
315 |
public String toString() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
316 |
StringBuilder sb = new StringBuilder(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
317 |
sb.append("streamid: ") |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
318 |
.append(streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
319 |
return sb.toString(); |
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 |
|
48083 | 322 |
private void receiveDataFrame(DataFrame df) { |
323 |
inputQ.add(df); |
|
324 |
sched.runOrSchedule(); |
|
325 |
} |
|
326 |
||
327 |
/** Handles a RESET frame. RESET is always handled inline in the queue. */ |
|
328 |
private void receiveResetFrame(ResetFrame frame) { |
|
329 |
inputQ.add(frame); |
|
330 |
sched.runOrSchedule(); |
|
43984 | 331 |
} |
332 |
||
48083 | 333 |
// pushes entire response body into response subscriber |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
334 |
// blocking when required by local or remote flow control |
49765 | 335 |
CompletableFuture<T> receiveData(BodySubscriber<T> bodySubscriber, Executor executor) { |
336 |
// We want to allow the subscriber's getBody() method to block so it |
|
337 |
// can work with InputStreams. So, we offload execution. |
|
53467
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
52554
diff
changeset
|
338 |
responseBodyCF = ResponseSubscribers.getBodyAsync(executor, bodySubscriber, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
52554
diff
changeset
|
339 |
new MinimalFuture<>(), this::cancelImpl); |
48083 | 340 |
|
341 |
if (isCanceled()) { |
|
342 |
Throwable t = getCancelCause(); |
|
343 |
responseBodyCF.completeExceptionally(t); |
|
43984 | 344 |
} else { |
49765 | 345 |
pendingResponseSubscriber = bodySubscriber; |
346 |
sched.runOrSchedule(); // in case data waiting already to be processed |
|
43984 | 347 |
} |
48083 | 348 |
return responseBodyCF; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
349 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
350 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
351 |
@Override |
43984 | 352 |
CompletableFuture<ExchangeImpl<T>> sendBodyAsync() { |
353 |
return sendBodyImpl().thenApply( v -> this); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
354 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
355 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
356 |
@SuppressWarnings("unchecked") |
48083 | 357 |
Stream(Http2Connection connection, |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
358 |
Exchange<T> e, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
359 |
WindowController windowController) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
360 |
{ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
361 |
super(e); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
362 |
this.connection = connection; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
363 |
this.windowController = windowController; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
364 |
this.request = e.request(); |
48083 | 365 |
this.requestPublisher = request.requestPublisher; // may be null |
50681 | 366 |
this.responseHeadersBuilder = new HttpHeadersBuilder(); |
367 |
this.rspHeadersConsumer = new HeadersConsumer(); |
|
368 |
this.requestPseudoHeaders = createPseudoHeaders(request); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
369 |
this.windowUpdater = new StreamWindowUpdateSender(connection); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
370 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
371 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
372 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
373 |
* Entry point from Http2Connection reader thread. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
374 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
375 |
* Data frames will be removed by response body thread. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
376 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
377 |
void incoming(Http2Frame frame) throws IOException { |
49765 | 378 |
if (debug.on()) debug.log("incoming: %s", frame); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
379 |
if ((frame instanceof HeaderFrame)) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
380 |
HeaderFrame hframe = (HeaderFrame)frame; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
381 |
if (hframe.endHeaders()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
382 |
Log.logTrace("handling response (streamid={0})", streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
383 |
handleResponse(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
384 |
if (hframe.getFlag(HeaderFrame.END_STREAM)) { |
48083 | 385 |
receiveDataFrame(new DataFrame(streamid, DataFrame.END_STREAM, List.of())); |
42460
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 |
} else if (frame instanceof DataFrame) { |
48083 | 389 |
receiveDataFrame((DataFrame)frame); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
390 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
391 |
otherFrame(frame); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
392 |
} |
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 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
395 |
void otherFrame(Http2Frame frame) throws IOException { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
396 |
switch (frame.type()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
397 |
case WindowUpdateFrame.TYPE: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
398 |
incoming_windowUpdate((WindowUpdateFrame) frame); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
399 |
break; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
400 |
case ResetFrame.TYPE: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
401 |
incoming_reset((ResetFrame) frame); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
402 |
break; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
403 |
case PriorityFrame.TYPE: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
404 |
incoming_priority((PriorityFrame) frame); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
405 |
break; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
406 |
default: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
407 |
String msg = "Unexpected frame: " + frame.toString(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
408 |
throw new IOException(msg); |
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 |
} |
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 |
// The Hpack decoder decodes into one of these consumers of name,value pairs |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
413 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
414 |
DecodingCallback rspHeadersConsumer() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
415 |
return rspHeadersConsumer; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
416 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
417 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
418 |
protected void handleResponse() throws IOException { |
50681 | 419 |
HttpHeaders responseHeaders = responseHeadersBuilder.build(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
420 |
responseCode = (int)responseHeaders |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
421 |
.firstValueAsLong(":status") |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
422 |
.orElseThrow(() -> new IOException("no statuscode in response")); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
423 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
424 |
response = new Response( |
49765 | 425 |
request, exchange, responseHeaders, connection(), |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
426 |
responseCode, HttpClient.Version.HTTP_2); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
427 |
|
48083 | 428 |
/* TODO: review if needs to be removed |
429 |
the value is not used, but in case `content-length` doesn't parse as |
|
430 |
long, there will be NumberFormatException. If left as is, make sure |
|
431 |
code up the stack handles NFE correctly. */ |
|
432 |
responseHeaders.firstValueAsLong("content-length"); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
433 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
434 |
if (Log.headers()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
435 |
StringBuilder sb = new StringBuilder("RESPONSE HEADERS:\n"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
436 |
Log.dumpHeaders(sb, " ", responseHeaders); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
437 |
Log.logHeaders(sb.toString()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
438 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
439 |
|
49765 | 440 |
// this will clear the response headers |
441 |
rspHeadersConsumer.reset(); |
|
442 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
443 |
completeResponse(response); |
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 |
|
48083 | 446 |
void incoming_reset(ResetFrame frame) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
447 |
Log.logTrace("Received RST_STREAM on stream {0}", streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
448 |
if (endStreamReceived()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
449 |
Log.logTrace("Ignoring RST_STREAM frame received on remotely closed stream {0}", streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
450 |
} else if (closed) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
451 |
Log.logTrace("Ignoring RST_STREAM frame received on closed stream {0}", streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
452 |
} else { |
50681 | 453 |
Flow.Subscriber<?> subscriber = |
454 |
responseSubscriber == null ? pendingResponseSubscriber : responseSubscriber; |
|
455 |
if (response == null && subscriber == null) { |
|
456 |
// we haven't receive the headers yet, and won't receive any! |
|
457 |
// handle reset now. |
|
458 |
handleReset(frame, subscriber); |
|
459 |
} else { |
|
460 |
// put it in the input queue in order to read all |
|
461 |
// pending data frames first. Indeed, a server may send |
|
462 |
// RST_STREAM after sending END_STREAM, in which case we should |
|
463 |
// ignore it. However, we won't know if we have received END_STREAM |
|
464 |
// or not until all pending data frames are read. |
|
465 |
receiveResetFrame(frame); |
|
466 |
// RST_STREAM was pushed to the queue. It will be handled by |
|
467 |
// asyncReceive after all pending data frames have been |
|
468 |
// processed. |
|
469 |
Log.logTrace("RST_STREAM pushed in queue for stream {0}", streamid); |
|
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 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
473 |
|
50681 | 474 |
void handleReset(ResetFrame frame, Flow.Subscriber<?> subscriber) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
475 |
Log.logTrace("Handling RST_STREAM on stream {0}", streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
476 |
if (!closed) { |
50681 | 477 |
synchronized (this) { |
478 |
if (closed) { |
|
479 |
if (debug.on()) debug.log("Stream already closed: ignoring RESET"); |
|
480 |
return; |
|
481 |
} |
|
482 |
closed = true; |
|
483 |
} |
|
484 |
try { |
|
485 |
int error = frame.getErrorCode(); |
|
486 |
IOException e = new IOException("Received RST_STREAM: " |
|
487 |
+ ErrorFrame.stringForCode(error)); |
|
488 |
if (errorRef.compareAndSet(null, e)) { |
|
489 |
if (subscriber != null) { |
|
490 |
subscriber.onError(e); |
|
491 |
} |
|
492 |
} |
|
493 |
completeResponseExceptionally(e); |
|
494 |
if (!requestBodyCF.isDone()) { |
|
495 |
requestBodyCF.completeExceptionally(errorRef.get()); // we may be sending the body.. |
|
496 |
} |
|
497 |
if (responseBodyCF != null) { |
|
498 |
responseBodyCF.completeExceptionally(errorRef.get()); |
|
499 |
} |
|
500 |
} finally { |
|
501 |
connection.decrementStreamsCount(streamid); |
|
502 |
connection.closeStream(streamid); |
|
503 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
504 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
505 |
Log.logTrace("Ignoring RST_STREAM frame received on closed stream {0}", streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
506 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
507 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
508 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
509 |
void incoming_priority(PriorityFrame frame) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
510 |
// TODO: implement priority |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
511 |
throw new UnsupportedOperationException("Not implemented"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
512 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
513 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
514 |
private void incoming_windowUpdate(WindowUpdateFrame frame) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
515 |
throws IOException |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
516 |
{ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
517 |
int amount = frame.getUpdate(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
518 |
if (amount <= 0) { |
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
519 |
Log.logTrace("Resetting stream: {0}, Window Update amount: {1}", |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
520 |
streamid, amount); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
521 |
connection.resetStream(streamid, ResetFrame.FLOW_CONTROL_ERROR); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
522 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
523 |
assert streamid != 0; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
524 |
boolean success = windowController.increaseStreamWindow(amount, streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
525 |
if (!success) { // overflow |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
526 |
connection.resetStream(streamid, ResetFrame.FLOW_CONTROL_ERROR); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
527 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
528 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
529 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
530 |
|
49765 | 531 |
void incoming_pushPromise(HttpRequestImpl pushRequest, |
532 |
PushedStream<T> pushStream) |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
533 |
throws IOException |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
534 |
{ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
535 |
if (Log.requests()) { |
49765 | 536 |
Log.logRequest("PUSH_PROMISE: " + pushRequest.toString()); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
537 |
} |
49765 | 538 |
PushGroup<T> pushGroup = exchange.getPushGroup(); |
48523
b95b08f3e1a8
8194883: Unhandleable Push Promises should be cancelled
chegar
parents:
48083
diff
changeset
|
539 |
if (pushGroup == null) { |
b95b08f3e1a8
8194883: Unhandleable Push Promises should be cancelled
chegar
parents:
48083
diff
changeset
|
540 |
Log.logTrace("Rejecting push promise stream " + streamid); |
b95b08f3e1a8
8194883: Unhandleable Push Promises should be cancelled
chegar
parents:
48083
diff
changeset
|
541 |
connection.resetStream(pushStream.streamid, ResetFrame.REFUSED_STREAM); |
b95b08f3e1a8
8194883: Unhandleable Push Promises should be cancelled
chegar
parents:
48083
diff
changeset
|
542 |
pushStream.close(); |
48083 | 543 |
return; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
544 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
545 |
|
49765 | 546 |
PushGroup.Acceptor<T> acceptor = null; |
547 |
boolean accepted = false; |
|
548 |
try { |
|
549 |
acceptor = pushGroup.acceptPushRequest(pushRequest); |
|
550 |
accepted = acceptor.accepted(); |
|
551 |
} catch (Throwable t) { |
|
552 |
if (debug.on()) |
|
553 |
debug.log("PushPromiseHandler::applyPushPromise threw exception %s", |
|
554 |
(Object)t); |
|
555 |
} |
|
556 |
if (!accepted) { |
|
557 |
// cancel / reject |
|
558 |
IOException ex = new IOException("Stream " + streamid + " cancelled by users handler"); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
559 |
if (Log.trace()) { |
49765 | 560 |
Log.logTrace("No body subscriber for {0}: {1}", pushRequest, |
561 |
ex.getMessage()); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
562 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
563 |
pushStream.cancelImpl(ex); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
564 |
return; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
565 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
566 |
|
49765 | 567 |
assert accepted && acceptor != null; |
568 |
CompletableFuture<HttpResponse<T>> pushResponseCF = acceptor.cf(); |
|
569 |
HttpResponse.BodyHandler<T> pushHandler = acceptor.bodyHandler(); |
|
570 |
assert pushHandler != null; |
|
571 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
572 |
pushStream.requestSent(); |
49765 | 573 |
pushStream.setPushHandler(pushHandler); // TODO: could wrap the handler to throw on acceptPushPromise ? |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
574 |
// setup housekeeping for when the push is received |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
575 |
// TODO: deal with ignoring of CF anti-pattern |
49765 | 576 |
CompletableFuture<HttpResponse<T>> cf = pushStream.responseCF(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
577 |
cf.whenComplete((HttpResponse<T> resp, Throwable t) -> { |
48083 | 578 |
t = Utils.getCompletionCause(t); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
579 |
if (Log.trace()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
580 |
Log.logTrace("Push completed on stream {0} for {1}{2}", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
581 |
pushStream.streamid, resp, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
582 |
((t==null) ? "": " with exception " + t)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
583 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
584 |
if (t != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
585 |
pushGroup.pushError(t); |
49765 | 586 |
pushResponseCF.completeExceptionally(t); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
587 |
} else { |
49765 | 588 |
pushResponseCF.complete(resp); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
589 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
590 |
pushGroup.pushCompleted(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
591 |
}); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
592 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
593 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
594 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
595 |
private OutgoingHeaders<Stream<T>> headerFrame(long contentLength) { |
50681 | 596 |
HttpHeadersBuilder h = request.getSystemHeadersBuilder(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
597 |
if (contentLength > 0) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
598 |
h.setHeader("content-length", Long.toString(contentLength)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
599 |
} |
50681 | 600 |
HttpHeaders sysh = filterHeaders(h.build()); |
601 |
HttpHeaders userh = filterHeaders(request.getUserHeaders()); |
|
52554
5f1ca46703f9
8213189: Make restricted headers in HTTP Client configurable and remove Date by default
michaelm
parents:
52499
diff
changeset
|
602 |
// Filter context restricted from userHeaders |
5f1ca46703f9
8213189: Make restricted headers in HTTP Client configurable and remove Date by default
michaelm
parents:
52499
diff
changeset
|
603 |
userh = HttpHeaders.of(userh.map(), Utils.CONTEXT_RESTRICTED(client())); |
5f1ca46703f9
8213189: Make restricted headers in HTTP Client configurable and remove Date by default
michaelm
parents:
52499
diff
changeset
|
604 |
|
5f1ca46703f9
8213189: Make restricted headers in HTTP Client configurable and remove Date by default
michaelm
parents:
52499
diff
changeset
|
605 |
final HttpHeaders uh = userh; |
5f1ca46703f9
8213189: Make restricted headers in HTTP Client configurable and remove Date by default
michaelm
parents:
52499
diff
changeset
|
606 |
|
5f1ca46703f9
8213189: Make restricted headers in HTTP Client configurable and remove Date by default
michaelm
parents:
52499
diff
changeset
|
607 |
// Filter any headers from systemHeaders that are set in userHeaders |
5f1ca46703f9
8213189: Make restricted headers in HTTP Client configurable and remove Date by default
michaelm
parents:
52499
diff
changeset
|
608 |
sysh = HttpHeaders.of(sysh.map(), (k,v) -> uh.firstValue(k).isEmpty()); |
5f1ca46703f9
8213189: Make restricted headers in HTTP Client configurable and remove Date by default
michaelm
parents:
52499
diff
changeset
|
609 |
|
49765 | 610 |
OutgoingHeaders<Stream<T>> f = new OutgoingHeaders<>(sysh, userh, this); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
611 |
if (contentLength == 0) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
612 |
f.setFlag(HeadersFrame.END_STREAM); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
613 |
endStreamSent = true; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
614 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
615 |
return f; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
616 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
617 |
|
49765 | 618 |
private boolean hasProxyAuthorization(HttpHeaders headers) { |
619 |
return headers.firstValue("proxy-authorization") |
|
620 |
.isPresent(); |
|
621 |
} |
|
622 |
||
623 |
// Determines whether we need to build a new HttpHeader object. |
|
624 |
// |
|
625 |
// Ideally we should pass the filter to OutgoingHeaders refactor the |
|
626 |
// code that creates the HeaderFrame to honor the filter. |
|
627 |
// We're not there yet - so depending on the filter we need to |
|
628 |
// apply and the content of the header we will try to determine |
|
629 |
// whether anything might need to be filtered. |
|
630 |
// If nothing needs filtering then we can just use the |
|
631 |
// original headers. |
|
632 |
private boolean needsFiltering(HttpHeaders headers, |
|
50681 | 633 |
BiPredicate<String, String> filter) { |
49765 | 634 |
if (filter == Utils.PROXY_TUNNEL_FILTER || filter == Utils.PROXY_FILTER) { |
635 |
// we're either connecting or proxying |
|
636 |
// slight optimization: we only need to filter out |
|
637 |
// disabled schemes, so if there are none just |
|
638 |
// pass through. |
|
639 |
return Utils.proxyHasDisabledSchemes(filter == Utils.PROXY_TUNNEL_FILTER) |
|
640 |
&& hasProxyAuthorization(headers); |
|
641 |
} else { |
|
642 |
// we're talking to a server, either directly or through |
|
643 |
// a tunnel. |
|
644 |
// Slight optimization: we only need to filter out |
|
645 |
// proxy authorization headers, so if there are none just |
|
646 |
// pass through. |
|
647 |
return hasProxyAuthorization(headers); |
|
648 |
} |
|
649 |
} |
|
650 |
||
50681 | 651 |
private HttpHeaders filterHeaders(HttpHeaders headers) { |
49765 | 652 |
HttpConnection conn = connection(); |
50681 | 653 |
BiPredicate<String, String> filter = conn.headerFilter(request); |
49765 | 654 |
if (needsFiltering(headers, filter)) { |
50681 | 655 |
return HttpHeaders.of(headers.map(), filter); |
49765 | 656 |
} |
657 |
return headers; |
|
658 |
} |
|
659 |
||
50681 | 660 |
private static HttpHeaders createPseudoHeaders(HttpRequest request) { |
661 |
HttpHeadersBuilder hdrs = new HttpHeadersBuilder(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
662 |
String method = request.method(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
663 |
hdrs.setHeader(":method", method); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
664 |
URI uri = request.uri(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
665 |
hdrs.setHeader(":scheme", uri.getScheme()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
666 |
// TODO: userinfo deprecated. Needs to be removed |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
667 |
hdrs.setHeader(":authority", uri.getAuthority()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
668 |
// TODO: ensure header names beginning with : not in user headers |
49765 | 669 |
String query = uri.getRawQuery(); |
670 |
String path = uri.getRawPath(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
671 |
if (path == null || path.isEmpty()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
672 |
if (method.equalsIgnoreCase("OPTIONS")) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
673 |
path = "*"; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
674 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
675 |
path = "/"; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
676 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
677 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
678 |
if (query != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
679 |
path += "?" + query; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
680 |
} |
49944 | 681 |
hdrs.setHeader(":path", Utils.encode(path)); |
50681 | 682 |
return hdrs.build(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
683 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
684 |
|
50681 | 685 |
HttpHeaders getRequestPseudoHeaders() { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
686 |
return requestPseudoHeaders; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
687 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
688 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
689 |
/** Sets endStreamReceived. Should be called only once. */ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
690 |
void setEndStreamReceived() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
691 |
assert remotelyClosed == false: "Unexpected endStream already set"; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
692 |
remotelyClosed = true; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
693 |
responseReceived(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
694 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
695 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
696 |
/** Tells whether, or not, the END_STREAM Flag has been seen in any frame |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
697 |
* received on this stream. */ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
698 |
private boolean endStreamReceived() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
699 |
return remotelyClosed; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
700 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
701 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
702 |
@Override |
48083 | 703 |
CompletableFuture<ExchangeImpl<T>> sendHeadersAsync() { |
49765 | 704 |
if (debug.on()) debug.log("sendHeadersOnly()"); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
705 |
if (Log.requests() && request != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
706 |
Log.logRequest(request.toString()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
707 |
} |
48083 | 708 |
if (requestPublisher != null) { |
709 |
requestContentLen = requestPublisher.contentLength(); |
|
710 |
} else { |
|
711 |
requestContentLen = 0; |
|
712 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
713 |
OutgoingHeaders<Stream<T>> f = headerFrame(requestContentLen); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
714 |
connection.sendFrame(f); |
48083 | 715 |
CompletableFuture<ExchangeImpl<T>> cf = new MinimalFuture<>(); |
716 |
cf.complete(this); // #### good enough for now |
|
717 |
return cf; |
|
718 |
} |
|
719 |
||
720 |
@Override |
|
721 |
void released() { |
|
722 |
if (streamid > 0) { |
|
49765 | 723 |
if (debug.on()) debug.log("Released stream %d", streamid); |
48083 | 724 |
// remove this stream from the Http2Connection map. |
50681 | 725 |
connection.decrementStreamsCount(streamid); |
48083 | 726 |
connection.closeStream(streamid); |
727 |
} else { |
|
49765 | 728 |
if (debug.on()) debug.log("Can't release stream %d", streamid); |
48083 | 729 |
} |
730 |
} |
|
731 |
||
732 |
@Override |
|
733 |
void completed() { |
|
734 |
// There should be nothing to do here: the stream should have |
|
735 |
// been already closed (or will be closed shortly after). |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
736 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
737 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
738 |
void registerStream(int id) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
739 |
this.streamid = id; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
740 |
connection.putStream(this, streamid); |
49765 | 741 |
if (debug.on()) debug.log("Registered stream %d", id); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
742 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
743 |
|
48083 | 744 |
void signalWindowUpdate() { |
745 |
RequestSubscriber subscriber = requestSubscriber; |
|
746 |
assert subscriber != null; |
|
49765 | 747 |
if (debug.on()) debug.log("Signalling window update"); |
48083 | 748 |
subscriber.sendScheduler.runOrSchedule(); |
749 |
} |
|
750 |
||
751 |
static final ByteBuffer COMPLETED = ByteBuffer.allocate(0); |
|
45708
3512073b446f
8178699: Fail to send async requests if server doesn't response the first one
xiaofeya
parents:
45531
diff
changeset
|
752 |
class RequestSubscriber implements Flow.Subscriber<ByteBuffer> { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
753 |
// can be < 0 if the actual length is not known. |
48083 | 754 |
private final long contentLength; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
755 |
private volatile long remainingContentLength; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
756 |
private volatile Subscription subscription; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
757 |
|
48083 | 758 |
// Holds the outgoing data. There will be at most 2 outgoing ByteBuffers. |
759 |
// 1) The data that was published by the request body Publisher, and |
|
760 |
// 2) the COMPLETED sentinel, since onComplete can be invoked without demand. |
|
761 |
final ConcurrentLinkedDeque<ByteBuffer> outgoing = new ConcurrentLinkedDeque<>(); |
|
762 |
||
763 |
private final AtomicReference<Throwable> errorRef = new AtomicReference<>(); |
|
764 |
// A scheduler used to honor window updates. Writing must be paused |
|
765 |
// when the window is exhausted, and resumed when the window acquires |
|
766 |
// some space. The sendScheduler makes it possible to implement this |
|
767 |
// behaviour in an asynchronous non-blocking way. |
|
768 |
// See RequestSubscriber::trySend below. |
|
769 |
final SequentialScheduler sendScheduler; |
|
770 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
771 |
RequestSubscriber(long contentLen) { |
48083 | 772 |
this.contentLength = contentLen; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
773 |
this.remainingContentLength = contentLen; |
48083 | 774 |
this.sendScheduler = |
775 |
SequentialScheduler.synchronizedScheduler(this::trySend); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
776 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
777 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
778 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
779 |
public void onSubscribe(Flow.Subscription subscription) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
780 |
if (this.subscription != null) { |
48083 | 781 |
throw new IllegalStateException("already subscribed"); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
782 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
783 |
this.subscription = subscription; |
49765 | 784 |
if (debug.on()) |
785 |
debug.log("RequestSubscriber: onSubscribe, request 1"); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
786 |
subscription.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
787 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
788 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
789 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
790 |
public void onNext(ByteBuffer item) { |
49765 | 791 |
if (debug.on()) |
792 |
debug.log("RequestSubscriber: onNext(%d)", item.remaining()); |
|
48083 | 793 |
int size = outgoing.size(); |
794 |
assert size == 0 : "non-zero size: " + size; |
|
795 |
onNextImpl(item); |
|
796 |
} |
|
797 |
||
798 |
private void onNextImpl(ByteBuffer item) { |
|
799 |
// Got some more request body bytes to send. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
800 |
if (requestBodyCF.isDone()) { |
48083 | 801 |
// stream already cancelled, probably in timeout |
802 |
sendScheduler.stop(); |
|
803 |
subscription.cancel(); |
|
804 |
return; |
|
805 |
} |
|
806 |
outgoing.add(item); |
|
807 |
sendScheduler.runOrSchedule(); |
|
808 |
} |
|
809 |
||
810 |
@Override |
|
811 |
public void onError(Throwable throwable) { |
|
49765 | 812 |
if (debug.on()) |
813 |
debug.log(() -> "RequestSubscriber: onError: " + throwable); |
|
48083 | 814 |
// ensure that errors are handled within the flow. |
815 |
if (errorRef.compareAndSet(null, throwable)) { |
|
816 |
sendScheduler.runOrSchedule(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
817 |
} |
48083 | 818 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
819 |
|
48083 | 820 |
@Override |
821 |
public void onComplete() { |
|
49765 | 822 |
if (debug.on()) debug.log("RequestSubscriber: onComplete"); |
48083 | 823 |
int size = outgoing.size(); |
824 |
assert size == 0 || size == 1 : "non-zero or one size: " + size; |
|
825 |
// last byte of request body has been obtained. |
|
826 |
// ensure that everything is completed within the flow. |
|
827 |
onNextImpl(COMPLETED); |
|
828 |
} |
|
829 |
||
830 |
// Attempts to send the data, if any. |
|
831 |
// Handles errors and completion state. |
|
832 |
// Pause writing if the send window is exhausted, resume it if the |
|
833 |
// send window has some bytes that can be acquired. |
|
834 |
void trySend() { |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
835 |
try { |
48083 | 836 |
// handle errors raised by onError; |
837 |
Throwable t = errorRef.get(); |
|
838 |
if (t != null) { |
|
839 |
sendScheduler.stop(); |
|
840 |
if (requestBodyCF.isDone()) return; |
|
841 |
subscription.cancel(); |
|
842 |
requestBodyCF.completeExceptionally(t); |
|
49765 | 843 |
cancelImpl(t); |
48083 | 844 |
return; |
845 |
} |
|
846 |
||
847 |
do { |
|
848 |
// handle COMPLETED; |
|
849 |
ByteBuffer item = outgoing.peekFirst(); |
|
850 |
if (item == null) return; |
|
851 |
else if (item == COMPLETED) { |
|
852 |
sendScheduler.stop(); |
|
853 |
complete(); |
|
854 |
return; |
|
855 |
} |
|
856 |
||
857 |
// handle bytes to send downstream |
|
858 |
while (item.hasRemaining()) { |
|
49765 | 859 |
if (debug.on()) debug.log("trySend: %d", item.remaining()); |
48083 | 860 |
assert !endStreamSent : "internal error, send data after END_STREAM flag"; |
861 |
DataFrame df = getDataFrame(item); |
|
862 |
if (df == null) { |
|
49765 | 863 |
if (debug.on()) |
864 |
debug.log("trySend: can't send yet: %d", item.remaining()); |
|
48083 | 865 |
return; // the send window is exhausted: come back later |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
866 |
} |
48083 | 867 |
|
868 |
if (contentLength > 0) { |
|
869 |
remainingContentLength -= df.getDataLength(); |
|
870 |
if (remainingContentLength < 0) { |
|
871 |
String msg = connection().getConnectionFlow() |
|
872 |
+ " stream=" + streamid + " " |
|
873 |
+ "[" + Thread.currentThread().getName() + "] " |
|
874 |
+ "Too many bytes in request body. Expected: " |
|
875 |
+ contentLength + ", got: " |
|
876 |
+ (contentLength - remainingContentLength); |
|
877 |
connection.resetStream(streamid, ResetFrame.PROTOCOL_ERROR); |
|
878 |
throw new IOException(msg); |
|
879 |
} else if (remainingContentLength == 0) { |
|
880 |
df.setFlag(DataFrame.END_STREAM); |
|
881 |
endStreamSent = true; |
|
882 |
} |
|
883 |
} |
|
49765 | 884 |
if (debug.on()) |
885 |
debug.log("trySend: sending: %d", df.getDataLength()); |
|
48083 | 886 |
connection.sendDataFrame(df); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
887 |
} |
48083 | 888 |
assert !item.hasRemaining(); |
889 |
ByteBuffer b = outgoing.removeFirst(); |
|
890 |
assert b == item; |
|
891 |
} while (outgoing.peekFirst() != null); |
|
892 |
||
49765 | 893 |
if (debug.on()) debug.log("trySend: request 1"); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
894 |
subscription.request(1); |
48083 | 895 |
} catch (Throwable ex) { |
49765 | 896 |
if (debug.on()) debug.log("trySend: ", ex); |
48083 | 897 |
sendScheduler.stop(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
898 |
subscription.cancel(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
899 |
requestBodyCF.completeExceptionally(ex); |
49765 | 900 |
// need to cancel the stream to 1. tell the server |
901 |
// we don't want to receive any more data and |
|
902 |
// 2. ensure that the operation ref count will be |
|
903 |
// decremented on the HttpClient. |
|
904 |
cancelImpl(ex); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
905 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
906 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
907 |
|
48083 | 908 |
private void complete() throws IOException { |
909 |
long remaining = remainingContentLength; |
|
910 |
long written = contentLength - remaining; |
|
911 |
if (remaining > 0) { |
|
912 |
connection.resetStream(streamid, ResetFrame.PROTOCOL_ERROR); |
|
913 |
// let trySend() handle the exception |
|
914 |
throw new IOException(connection().getConnectionFlow() |
|
915 |
+ " stream=" + streamid + " " |
|
916 |
+ "[" + Thread.currentThread().getName() +"] " |
|
917 |
+ "Too few bytes returned by the publisher (" |
|
918 |
+ written + "/" |
|
919 |
+ contentLength + ")"); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
920 |
} |
48083 | 921 |
if (!endStreamSent) { |
922 |
endStreamSent = true; |
|
923 |
connection.sendDataFrame(getEmptyEndStreamDataFrame()); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
924 |
} |
48083 | 925 |
requestBodyCF.complete(null); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
926 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
927 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
928 |
|
48083 | 929 |
/** |
930 |
* Send a RESET frame to tell server to stop sending data on this stream |
|
931 |
*/ |
|
932 |
@Override |
|
933 |
public CompletableFuture<Void> ignoreBody() { |
|
934 |
try { |
|
935 |
connection.resetStream(streamid, ResetFrame.STREAM_CLOSED); |
|
936 |
return MinimalFuture.completedFuture(null); |
|
937 |
} catch (Throwable e) { |
|
938 |
Log.logTrace("Error resetting stream {0}", e.toString()); |
|
939 |
return MinimalFuture.failedFuture(e); |
|
940 |
} |
|
941 |
} |
|
942 |
||
943 |
DataFrame getDataFrame(ByteBuffer buffer) { |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
944 |
int requestAmount = Math.min(connection.getMaxSendFrameSize(), buffer.remaining()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
945 |
// blocks waiting for stream send window, if exhausted |
48083 | 946 |
int actualAmount = windowController.tryAcquire(requestAmount, streamid, this); |
947 |
if (actualAmount <= 0) return null; |
|
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
48523
diff
changeset
|
948 |
ByteBuffer outBuf = Utils.sliceWithLimitedCapacity(buffer, actualAmount); |
48083 | 949 |
DataFrame df = new DataFrame(streamid, 0 , outBuf); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
950 |
return df; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
951 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
952 |
|
48083 | 953 |
private DataFrame getEmptyEndStreamDataFrame() { |
954 |
return new DataFrame(streamid, DataFrame.END_STREAM, List.of()); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
955 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
956 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
957 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
958 |
* A List of responses relating to this stream. Normally there is only |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
959 |
* one response, but intermediate responses like 100 are allowed |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
960 |
* and must be passed up to higher level before continuing. Deals with races |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
961 |
* such as if responses are returned before the CFs get created by |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
962 |
* getResponseAsync() |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
963 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
964 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
965 |
final List<CompletableFuture<Response>> response_cfs = new ArrayList<>(5); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
966 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
967 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
968 |
CompletableFuture<Response> getResponseAsync(Executor executor) { |
48083 | 969 |
CompletableFuture<Response> cf; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
970 |
// The code below deals with race condition that can be caused when |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
971 |
// completeResponse() is being called before getResponseAsync() |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
972 |
synchronized (response_cfs) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
973 |
if (!response_cfs.isEmpty()) { |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
974 |
// This CompletableFuture was created by completeResponse(). |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
975 |
// it will be already completed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
976 |
cf = response_cfs.remove(0); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
977 |
// if we find a cf here it should be already completed. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
978 |
// finding a non completed cf should not happen. just assert it. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
979 |
assert cf.isDone() : "Removing uncompleted response: could cause code to hang!"; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
980 |
} else { |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
981 |
// getResponseAsync() is called first. Create a CompletableFuture |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
982 |
// that will be completed by completeResponse() when |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
983 |
// completeResponse() is called. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
984 |
cf = new MinimalFuture<>(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
985 |
response_cfs.add(cf); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
986 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
987 |
} |
43984 | 988 |
if (executor != null && !cf.isDone()) { |
989 |
// protect from executing later chain of CompletableFuture operations from SelectorManager thread |
|
990 |
cf = cf.thenApplyAsync(r -> r, executor); |
|
991 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
992 |
Log.logTrace("Response future (stream={0}) is: {1}", streamid, cf); |
49765 | 993 |
PushGroup<?> pg = exchange.getPushGroup(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
994 |
if (pg != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
995 |
// if an error occurs make sure it is recorded in the PushGroup |
48083 | 996 |
cf = cf.whenComplete((t,e) -> pg.pushError(Utils.getCompletionCause(e))); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
997 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
998 |
return cf; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
999 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1000 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1001 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1002 |
* Completes the first uncompleted CF on list, and removes it. If there is no |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1003 |
* uncompleted CF then creates one (completes it) and adds to list |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1004 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1005 |
void completeResponse(Response resp) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1006 |
synchronized (response_cfs) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1007 |
CompletableFuture<Response> cf; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1008 |
int cfs_len = response_cfs.size(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1009 |
for (int i=0; i<cfs_len; i++) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1010 |
cf = response_cfs.get(i); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1011 |
if (!cf.isDone()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1012 |
Log.logTrace("Completing response (streamid={0}): {1}", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1013 |
streamid, cf); |
50681 | 1014 |
if (debug.on()) |
1015 |
debug.log("Completing responseCF(%d) with response headers", i); |
|
1016 |
response_cfs.remove(cf); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1017 |
cf.complete(resp); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1018 |
return; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
1019 |
} // else we found the previous response: just leave it alone. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1020 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1021 |
cf = MinimalFuture.completedFuture(resp); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1022 |
Log.logTrace("Created completed future (streamid={0}): {1}", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1023 |
streamid, cf); |
50681 | 1024 |
if (debug.on()) |
1025 |
debug.log("Adding completed responseCF(0) with response headers"); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1026 |
response_cfs.add(cf); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1027 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1028 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1029 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1030 |
// methods to update state and remove stream when finished |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1031 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1032 |
synchronized void requestSent() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1033 |
requestSent = true; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1034 |
if (responseReceived) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1035 |
close(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1036 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1037 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1038 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1039 |
synchronized void responseReceived() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1040 |
responseReceived = true; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1041 |
if (requestSent) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1042 |
close(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1043 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1044 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1045 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1046 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1047 |
* same as above but for errors |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1048 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1049 |
void completeResponseExceptionally(Throwable t) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1050 |
synchronized (response_cfs) { |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
1051 |
// use index to avoid ConcurrentModificationException |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
1052 |
// caused by removing the CF from within the loop. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
1053 |
for (int i = 0; i < response_cfs.size(); i++) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
43999
diff
changeset
|
1054 |
CompletableFuture<Response> cf = response_cfs.get(i); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1055 |
if (!cf.isDone()) { |
50681 | 1056 |
response_cfs.remove(i); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1057 |
cf.completeExceptionally(t); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1058 |
return; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1059 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1060 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1061 |
response_cfs.add(MinimalFuture.failedFuture(t)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1062 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1063 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1064 |
|
43984 | 1065 |
CompletableFuture<Void> sendBodyImpl() { |
48083 | 1066 |
requestBodyCF.whenComplete((v, t) -> requestSent()); |
49765 | 1067 |
try { |
1068 |
if (requestPublisher != null) { |
|
1069 |
final RequestSubscriber subscriber = new RequestSubscriber(requestContentLen); |
|
1070 |
requestPublisher.subscribe(requestSubscriber = subscriber); |
|
1071 |
} else { |
|
1072 |
// there is no request body, therefore the request is complete, |
|
1073 |
// END_STREAM has already sent with outgoing headers |
|
1074 |
requestBodyCF.complete(null); |
|
1075 |
} |
|
1076 |
} catch (Throwable t) { |
|
1077 |
cancelImpl(t); |
|
1078 |
requestBodyCF.completeExceptionally(t); |
|
48083 | 1079 |
} |
43984 | 1080 |
return requestBodyCF; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1081 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1082 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1083 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1084 |
void cancel() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1085 |
cancel(new IOException("Stream " + streamid + " cancelled")); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1086 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1087 |
|
49765 | 1088 |
void onSubscriptionError(Throwable t) { |
1089 |
errorRef.compareAndSet(null, t); |
|
1090 |
if (debug.on()) debug.log("Got subscription error: %s", (Object)t); |
|
1091 |
// This is the special case where the subscriber |
|
1092 |
// has requested an illegal number of items. |
|
1093 |
// In this case, the error doesn't come from |
|
1094 |
// upstream, but from downstream, and we need to |
|
1095 |
// handle the error without waiting for the inputQ |
|
1096 |
// to be exhausted. |
|
1097 |
stopRequested = true; |
|
1098 |
sched.runOrSchedule(); |
|
1099 |
} |
|
1100 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1101 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1102 |
void cancel(IOException cause) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1103 |
cancelImpl(cause); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1104 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1105 |
|
50681 | 1106 |
void connectionClosing(Throwable cause) { |
1107 |
Flow.Subscriber<?> subscriber = |
|
1108 |
responseSubscriber == null ? pendingResponseSubscriber : responseSubscriber; |
|
1109 |
errorRef.compareAndSet(null, cause); |
|
1110 |
if (subscriber != null && !sched.isStopped() && !inputQ.isEmpty()) { |
|
1111 |
sched.runOrSchedule(); |
|
1112 |
} else cancelImpl(cause); |
|
1113 |
} |
|
1114 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1115 |
// This method sends a RST_STREAM frame |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1116 |
void cancelImpl(Throwable e) { |
49765 | 1117 |
errorRef.compareAndSet(null, e); |
1118 |
if (debug.on()) debug.log("cancelling stream {0}: {1}", streamid, e); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1119 |
if (Log.trace()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1120 |
Log.logTrace("cancelling stream {0}: {1}\n", streamid, e); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1121 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1122 |
boolean closing; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1123 |
if (closing = !closed) { // assigning closing to !closed |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1124 |
synchronized (this) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1125 |
if (closing = !closed) { // assigning closing to !closed |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1126 |
closed=true; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1127 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1128 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1129 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1130 |
if (closing) { // true if the stream has not been closed yet |
49765 | 1131 |
if (responseSubscriber != null || pendingResponseSubscriber != null) |
48083 | 1132 |
sched.runOrSchedule(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1133 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1134 |
completeResponseExceptionally(e); |
48083 | 1135 |
if (!requestBodyCF.isDone()) { |
49765 | 1136 |
requestBodyCF.completeExceptionally(errorRef.get()); // we may be sending the body.. |
48083 | 1137 |
} |
1138 |
if (responseBodyCF != null) { |
|
49765 | 1139 |
responseBodyCF.completeExceptionally(errorRef.get()); |
48083 | 1140 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1141 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1142 |
// will send a RST_STREAM frame |
45531
fb3dbffad37b
8180044: java/net/httpclient/ManyRequests.java failed due to timeout
dfuchs
parents:
44639
diff
changeset
|
1143 |
if (streamid != 0) { |
50681 | 1144 |
connection.decrementStreamsCount(streamid); |
1145 |
e = Utils.getCompletionCause(e); |
|
1146 |
if (e instanceof EOFException) { |
|
1147 |
// read EOF: no need to try & send reset |
|
1148 |
connection.closeStream(streamid); |
|
1149 |
} else { |
|
1150 |
connection.resetStream(streamid, ResetFrame.CANCEL); |
|
1151 |
} |
|
45531
fb3dbffad37b
8180044: java/net/httpclient/ManyRequests.java failed due to timeout
dfuchs
parents:
44639
diff
changeset
|
1152 |
} |
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1153 |
} catch (Throwable ex) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1154 |
Log.logError(ex); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1155 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1156 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1157 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1158 |
// This method doesn't send any frame |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1159 |
void close() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1160 |
if (closed) return; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1161 |
synchronized(this) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1162 |
if (closed) return; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1163 |
closed = true; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1164 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1165 |
Log.logTrace("Closing stream {0}", streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1166 |
connection.closeStream(streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1167 |
Log.logTrace("Stream {0} closed", streamid); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1168 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1169 |
|
49765 | 1170 |
static class PushedStream<T> extends Stream<T> { |
1171 |
final PushGroup<T> pushGroup; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1172 |
// push streams need the response CF allocated up front as it is |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1173 |
// given directly to user via the multi handler callback function. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1174 |
final CompletableFuture<Response> pushCF; |
49765 | 1175 |
CompletableFuture<HttpResponse<T>> responseCF; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1176 |
final HttpRequestImpl pushReq; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1177 |
HttpResponse.BodyHandler<T> pushHandler; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1178 |
|
49765 | 1179 |
PushedStream(PushGroup<T> pushGroup, |
48083 | 1180 |
Http2Connection connection, |
1181 |
Exchange<T> pushReq) { |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1182 |
// ## no request body possible, null window controller |
48083 | 1183 |
super(connection, pushReq, null); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1184 |
this.pushGroup = pushGroup; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1185 |
this.pushReq = pushReq.request(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1186 |
this.pushCF = new MinimalFuture<>(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1187 |
this.responseCF = new MinimalFuture<>(); |
49765 | 1188 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1189 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1190 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1191 |
CompletableFuture<HttpResponse<T>> responseCF() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1192 |
return responseCF; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1193 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1194 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1195 |
synchronized void setPushHandler(HttpResponse.BodyHandler<T> pushHandler) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1196 |
this.pushHandler = pushHandler; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1197 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1198 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1199 |
synchronized HttpResponse.BodyHandler<T> getPushHandler() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1200 |
// ignored parameters to function can be used as BodyHandler |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1201 |
return this.pushHandler; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1202 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1203 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1204 |
// Following methods call the super class but in case of |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1205 |
// error record it in the PushGroup. The error method is called |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1206 |
// with a null value when no error occurred (is a no-op) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1207 |
@Override |
43984 | 1208 |
CompletableFuture<ExchangeImpl<T>> sendBodyAsync() { |
1209 |
return super.sendBodyAsync() |
|
48083 | 1210 |
.whenComplete((ExchangeImpl<T> v, Throwable t) |
1211 |
-> pushGroup.pushError(Utils.getCompletionCause(t))); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1212 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1213 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1214 |
@Override |
43984 | 1215 |
CompletableFuture<ExchangeImpl<T>> sendHeadersAsync() { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1216 |
return super.sendHeadersAsync() |
48083 | 1217 |
.whenComplete((ExchangeImpl<T> ex, Throwable t) |
1218 |
-> pushGroup.pushError(Utils.getCompletionCause(t))); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1219 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1220 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1221 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1222 |
CompletableFuture<Response> getResponseAsync(Executor executor) { |
48083 | 1223 |
CompletableFuture<Response> cf = pushCF.whenComplete( |
1224 |
(v, t) -> pushGroup.pushError(Utils.getCompletionCause(t))); |
|
43984 | 1225 |
if(executor!=null && !cf.isDone()) { |
1226 |
cf = cf.thenApplyAsync( r -> r, executor); |
|
1227 |
} |
|
1228 |
return cf; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1229 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1230 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1231 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1232 |
CompletableFuture<T> readBodyAsync( |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1233 |
HttpResponse.BodyHandler<T> handler, |
43999
4cc44dd9f14f
8164625: Pooled HttpConnection should be removed during close
prappo
parents:
43984
diff
changeset
|
1234 |
boolean returnConnectionToPool, |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1235 |
Executor executor) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1236 |
{ |
43999
4cc44dd9f14f
8164625: Pooled HttpConnection should be removed during close
prappo
parents:
43984
diff
changeset
|
1237 |
return super.readBodyAsync(handler, returnConnectionToPool, executor) |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1238 |
.whenComplete((v, t) -> pushGroup.pushError(t)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1239 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1240 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1241 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1242 |
void completeResponse(Response r) { |
48083 | 1243 |
Log.logResponse(r::toString); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1244 |
pushCF.complete(r); // not strictly required for push API |
48083 | 1245 |
// start reading the body using the obtained BodySubscriber |
43984 | 1246 |
CompletableFuture<Void> start = new MinimalFuture<>(); |
1247 |
start.thenCompose( v -> readBodyAsync(getPushHandler(), false, getExchange().executor())) |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1248 |
.whenComplete((T body, Throwable t) -> { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1249 |
if (t != null) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1250 |
responseCF.completeExceptionally(t); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1251 |
} else { |
48083 | 1252 |
HttpResponseImpl<T> resp = |
1253 |
new HttpResponseImpl<>(r.request, r, null, body, getExchange()); |
|
1254 |
responseCF.complete(resp); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1255 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1256 |
}); |
43984 | 1257 |
start.completeAsync(() -> null, getExchange().executor()); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1258 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1259 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1260 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1261 |
void completeResponseExceptionally(Throwable t) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1262 |
pushCF.completeExceptionally(t); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1263 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1264 |
|
48083 | 1265 |
// @Override |
1266 |
// synchronized void responseReceived() { |
|
1267 |
// super.responseReceived(); |
|
1268 |
// } |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1269 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1270 |
// create and return the PushResponseImpl |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1271 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1272 |
protected void handleResponse() { |
50681 | 1273 |
HttpHeaders responseHeaders = responseHeadersBuilder.build(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1274 |
responseCode = (int)responseHeaders |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1275 |
.firstValueAsLong(":status") |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1276 |
.orElse(-1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1277 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1278 |
if (responseCode == -1) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1279 |
completeResponseExceptionally(new IOException("No status code")); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1280 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1281 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1282 |
this.response = new Response( |
49765 | 1283 |
pushReq, exchange, responseHeaders, connection(), |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1284 |
responseCode, HttpClient.Version.HTTP_2); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1285 |
|
48083 | 1286 |
/* TODO: review if needs to be removed |
1287 |
the value is not used, but in case `content-length` doesn't parse |
|
1288 |
as long, there will be NumberFormatException. If left as is, make |
|
1289 |
sure code up the stack handles NFE correctly. */ |
|
1290 |
responseHeaders.firstValueAsLong("content-length"); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1291 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1292 |
if (Log.headers()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1293 |
StringBuilder sb = new StringBuilder("RESPONSE HEADERS"); |
49765 | 1294 |
sb.append(" (streamid=").append(streamid).append("):\n"); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1295 |
Log.dumpHeaders(sb, " ", responseHeaders); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1296 |
Log.logHeaders(sb.toString()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1297 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1298 |
|
49765 | 1299 |
rspHeadersConsumer.reset(); |
1300 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1301 |
// different implementations for normal streams and pushed streams |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1302 |
completeResponse(response); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1303 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1304 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1305 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1306 |
final class StreamWindowUpdateSender extends WindowUpdateSender { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1307 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1308 |
StreamWindowUpdateSender(Http2Connection connection) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1309 |
super(connection); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1310 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1311 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1312 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1313 |
int getStreamId() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1314 |
return streamid; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1315 |
} |
50985
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1316 |
|
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1317 |
@Override |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1318 |
String dbgString() { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1319 |
String dbg = dbgString; |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1320 |
if (dbg != null) return dbg; |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1321 |
if (streamid == 0) { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1322 |
return connection.dbgString() + ":WindowUpdateSender(stream: ?)"; |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1323 |
} else { |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1324 |
dbg = connection.dbgString() + ":WindowUpdateSender(stream: " + streamid + ")"; |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1325 |
return dbgString = dbg; |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1326 |
} |
cd41f34e548c
8206001: Enable TLS1.3 by default in Http Client
michaelm
parents:
50681
diff
changeset
|
1327 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1328 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1329 |
|
48083 | 1330 |
/** |
1331 |
* Returns true if this exchange was canceled. |
|
1332 |
* @return true if this exchange was canceled. |
|
1333 |
*/ |
|
1334 |
synchronized boolean isCanceled() { |
|
49765 | 1335 |
return errorRef.get() != null; |
48083 | 1336 |
} |
1337 |
||
1338 |
/** |
|
1339 |
* Returns the cause for which this exchange was canceled, if available. |
|
1340 |
* @return the cause for which this exchange was canceled, if available. |
|
1341 |
*/ |
|
1342 |
synchronized Throwable getCancelCause() { |
|
49765 | 1343 |
return errorRef.get(); |
48083 | 1344 |
} |
1345 |
||
1346 |
final String dbgString() { |
|
1347 |
return connection.dbgString() + "/Stream("+streamid+")"; |
|
1348 |
} |
|
49765 | 1349 |
|
1350 |
private class HeadersConsumer extends Http2Connection.ValidatingHeadersConsumer { |
|
1351 |
||
1352 |
void reset() { |
|
1353 |
super.reset(); |
|
50681 | 1354 |
responseHeadersBuilder.clear(); |
1355 |
debug.log("Response builder cleared, ready to receive new headers."); |
|
49765 | 1356 |
} |
1357 |
||
1358 |
@Override |
|
1359 |
public void onDecoded(CharSequence name, CharSequence value) |
|
50681 | 1360 |
throws UncheckedIOException |
49765 | 1361 |
{ |
1362 |
String n = name.toString(); |
|
1363 |
String v = value.toString(); |
|
1364 |
super.onDecoded(n, v); |
|
50681 | 1365 |
responseHeadersBuilder.addHeader(n, v); |
49765 | 1366 |
if (Log.headers() && Log.trace()) { |
1367 |
Log.logTrace("RECEIVED HEADER (streamid={0}): {1}: {2}", |
|
1368 |
streamid, n, v); |
|
1369 |
} |
|
1370 |
} |
|
1371 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1372 |
} |