src/java.net.http/share/classes/jdk/internal/net/http/Stream.java
branchhttp-client-branch
changeset 56166 56c52d6417d1
parent 56165 8a6065d830b9
child 56200 d712a6342387
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Stream.java	Thu Feb 22 17:33:21 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Stream.java	Fri Feb 23 16:25:32 2018 +0000
@@ -113,8 +113,8 @@
 
     final Http2Connection connection;
     final HttpRequestImpl request;
-    final DecodingCallback rspHeadersConsumer;
-    HttpHeadersImpl responseHeaders;
+    final HeadersConsumer rspHeadersConsumer;
+    final HttpHeadersImpl responseHeaders;
     final HttpHeadersImpl requestPseudoHeaders;
     volatile HttpResponse.BodySubscriber<T> responseSubscriber;
     final HttpRequest.BodyPublisher requestPublisher;
@@ -232,7 +232,7 @@
     {
         try {
             Log.logTrace("Reading body on stream {0}", streamid);
-            BodySubscriber<T> bodySubscriber = handler.apply(responseCode, responseHeaders);
+            BodySubscriber<T> bodySubscriber = handler.apply(responseCode, response.headers);
             CompletableFuture<T> cf = receiveData(bodySubscriber, executor);
 
             PushGroup<?> pg = exchange.getPushGroup();
@@ -243,6 +243,7 @@
             return cf;
         } catch (Throwable t) {
             // may be thrown by handler.apply
+            cancelImpl(t);
             return MinimalFuture.failedFuture(t);
         }
     }
@@ -387,6 +388,9 @@
             Log.logHeaders(sb.toString());
         }
 
+        // this will clear the response headers
+        rspHeadersConsumer.reset();
+
         completeResponse(response);
     }
 
@@ -1145,6 +1149,8 @@
                 Log.logHeaders(sb.toString());
             }
 
+            rspHeadersConsumer.reset();
+
             // different implementations for normal streams and pushed streams
             completeResponse(response);
         }
@@ -1184,6 +1190,10 @@
 
     private class HeadersConsumer extends Http2Connection.ValidatingHeadersConsumer {
 
+        void reset() {
+            responseHeaders.clear();
+        }
+
         @Override
         public void onDecoded(CharSequence name, CharSequence value)
                 throws UncheckedIOException