ok2c commented on a change in pull request #153: HTTPCLIENT-1992: Impossible to 
access trailer-headers 
URL: 
https://github.com/apache/httpcomponents-client/pull/153#discussion_r293283436
 
 

 ##########
 File path: 
httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ChunkAwareResponseEntityProxy.java
 ##########
 @@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.impl.classic;
+
+import org.apache.hc.client5.http.classic.ExecRuntime;
+import org.apache.hc.core5.function.Supplier;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.impl.io.ChunkedInputStream;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+class ChunkAwareResponseEntityProxy extends ResponseEntityProxy {
+
+    private ChunkedInputStream internalChunkedInputStream;
+
+    public static void enhanceChunkedResponseSupport(final ClassicHttpResponse 
response, final ExecRuntime execRuntime) throws IOException {
+        final HttpEntity entity = response.getEntity();
+        if (!(entity.getContent() instanceof ChunkedInputStream)) {
+            throw new IllegalStateException("Underlying stream is not 
ChunkedInputStream, unable to reach footers.");
+        }
+        final ChunkedInputStream content = (ChunkedInputStream) 
entity.getContent();
+        if (entity != null && entity.isStreaming() && execRuntime != null) {
+            response.setEntity(new ChunkAwareResponseEntityProxy(entity, 
execRuntime, content));
+        }
+    }
+
+    ChunkAwareResponseEntityProxy(final HttpEntity entity, final ExecRuntime 
execRuntime, final ChunkedInputStream chunkedInputStream) {
+        super(entity, execRuntime);
+        this.internalChunkedInputStream = chunkedInputStream;
+    }
+
+    @Override
+    public Supplier<List<? extends Header>> getTrailers() {
 
 Review comment:
   @serkanturgut As far as I can say simpler is _better_. Looks good to me. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to