Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A155F1015A for ; Wed, 6 Nov 2013 10:38:23 +0000 (UTC) Received: (qmail 29946 invoked by uid 500); 6 Nov 2013 10:38:23 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 29846 invoked by uid 500); 6 Nov 2013 10:38:18 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 29833 invoked by uid 99); 6 Nov 2013 10:38:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Nov 2013 10:38:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Nov 2013 10:38:15 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1F6D423888E7 for ; Wed, 6 Nov 2013 10:37:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131106103755.1F6D423888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 + * [HTTPCLIENT-1431] (Regression) deprecated connection manager cannot be used with a custom LayeredSchemeSocketFactory. Contributed by Oleg Kalnichevski 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 + * . + * + */ +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