hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1539302 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java
Date Wed, 06 Nov 2013 10:37:54 GMT
Author: olegk
Date: Wed Nov  6 10:37:54 2013
New Revision: 1539302

URL: http://svn.apache.org/r1539302
Log:
HTTPCLIENT-1432: Lazy decompressing of HttpEntity#getContent() to avoid EOFExceptionin case
of an empty response with 'Content-Encoding: gzip' header.
Contributed by Yihua Huang <code4crafter at gmail.com>

Added:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1539302&r1=1539301&r2=1539302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Wed Nov  6 10:37:54 2013
@@ -1,6 +1,10 @@
 Changes since 4.3.1
 -------------------
 
+* [HTTPCLIENT-1432] Lazy decompressing of HttpEntity#getContent() to avoid EOFException
+  in case of an empty response with 'Content-Encoding: gzip' header.
+  Contributed by Yihua Huang <code4crafter at gmail.com>
+
 * [HTTPCLIENT-1431] (Regression) deprecated connection manager cannot be used with
   a custom LayeredSchemeSocketFactory.
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java?rev=1539302&r1=1539301&r2=1539302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
Wed Nov  6 10:37:54 2013
@@ -66,12 +66,7 @@ abstract class DecompressingEntity exten
 
     private InputStream getDecompressingStream() throws IOException {
         final InputStream in = wrappedEntity.getContent();
-        try {
-            return decorate(in);
-        } catch (final IOException ex) {
-            in.close();
-            throw ex;
-        }
+        return new LazyDecompressingInputStream(in, this);
     }
 
     /**

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java?rev=1539302&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java
Wed Nov  6 10:37:54 2013
@@ -0,0 +1,79 @@
+/*
+ * ====================================================================
+ * 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.http.client.entity;
+
+import org.apache.http.annotation.NotThreadSafe;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Lazy init InputStream wrapper.
+ */
+@NotThreadSafe
+class LazyDecompressingInputStream extends InputStream {
+
+    private final InputStream wrappedStream;
+
+    private final DecompressingEntity decompressingEntity;
+
+    private InputStream wrapperStream;
+
+    public LazyDecompressingInputStream(
+            final InputStream wrappedStream,
+            final DecompressingEntity decompressingEntity) {
+        this.wrappedStream = wrappedStream;
+        this.decompressingEntity = decompressingEntity;
+    }
+
+    @Override
+    public int read() throws IOException {
+        initWrapper();
+        return wrapperStream.read();
+    }
+
+    @Override
+    public int available() throws IOException {
+        initWrapper();
+        return wrapperStream.available();
+    }
+
+    private void initWrapper() throws IOException {
+        if (wrapperStream == null) {
+            wrapperStream = decompressingEntity.decorate(wrappedStream);
+        }
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (wrapperStream != null) {
+            wrapperStream.close();
+        }
+        wrappedStream.close();
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/LazyDecompressingInputStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message