Bug 61058 - HTTP Request : Deflate triggers "Unexpected end of ZLIB input stream"

Contributed by UbikLoadPack
Bugzilla Id: 61058

git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1825998 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Philippe Mouawad 2018-03-06 16:20:04 +00:00
parent c30fe1e2aa
commit 5795ff3e57
3 changed files with 97 additions and 2 deletions

View File

@ -71,7 +71,6 @@ import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.AuthSchemes;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.DeflateInputStream;
import org.apache.http.client.entity.InputStreamFactory;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
@ -146,6 +145,7 @@ import org.apache.jmeter.protocol.http.control.CacheManager;
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.DynamicKerberosSchemeFactory;
import org.apache.jmeter.protocol.http.control.HeaderManager;
import org.apache.jmeter.protocol.http.sampler.hc.LaxDeflateInputStream;
import org.apache.jmeter.protocol.http.sampler.hc.LazyLayeredConnectionSocketFactory;
import org.apache.jmeter.protocol.http.util.EncoderCache;
import org.apache.jmeter.protocol.http.util.HTTPArgument;
@ -189,6 +189,8 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
private static final int MAX_BODY_RETAIN_SIZE = JMeterUtils.getPropDefault("httpclient4.max_body_retain_size", 32 * 1024);
private static final boolean DEFLATE_RELAX_MODE = JMeterUtils.getPropDefault("httpclient4.deflate_relax_mode", false);
private static final Logger log = LoggerFactory.getLogger(HTTPHC4Impl.class);
private static final InputStreamFactory GZIP = new InputStreamFactory() {
@ -201,7 +203,7 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
private static final InputStreamFactory DEFLATE = new InputStreamFactory() {
@Override
public InputStream create(final InputStream instream) throws IOException {
return new DeflateInputStream(instream);
return new LaxDeflateInputStream(instream, DEFLATE_RELAX_MODE);
}
};

View File

@ -0,0 +1,92 @@
/*
* 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.
*
*/
package org.apache.jmeter.protocol.http.sampler.hc;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.client.entity.DeflateInputStream;
import org.apache.http.client.entity.DeflateInputStreamFactory;
/**
* {@link DeflateInputStreamFactory} subclass that has a flag to accept
* "edgy streams" that signal end of stream with {@link EOFException}
* which seems to be rather frequent
*
* @see https://bz.apache.org/bugzilla/show_bug.cgi?id=61058
* @since 4.1
*/
public class LaxDeflateInputStream extends DeflateInputStream {
private final boolean relax;
/**
* @param wrapped
* @param relax
* @throws IOException
*/
public LaxDeflateInputStream(InputStream wrapped, boolean relax) throws IOException {
super(wrapped);
this.relax = relax;
}
/* (non-Javadoc)
* @see org.apache.http.client.entity.DeflateInputStream#read(byte[], int, int)
*/
@Override
public int read(byte[] b, int off, int len) throws IOException {
try {
return super.read(b, off, len);
} catch (final EOFException ex) {
return handleRelaxMode(ex, relax);
}
}
@Override
public int read() throws IOException {
try {
return super.read();
} catch (final EOFException ex) {
return handleRelaxMode(ex, relax);
}
}
@Override
public int read(byte[] b) throws IOException {
try {
return super.read(b);
} catch (final EOFException ex) {
return handleRelaxMode(ex, relax);
}
}
/**
* @param ex EOFException
* @param relaxMode relax mode enabled
* @return -1 if relax
* @throws EOFException
*/
private int handleRelaxMode(final EOFException ex, final boolean relaxMode) throws EOFException {
if(relaxMode) {
return -1;
} else {
throw ex;
}
}
}

View File

@ -140,6 +140,7 @@ this behaviour, set <code>httpclient.reset_state_on_thread_group_iteration=false
<h3>HTTP Samplers and Test Script Recorder</h3>
<ul>
<li><bug>62114</bug>HTTP(S) Test Script Recorder : Client certificate authentication uses the first SSLManager created. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
<li><bug>61058</bug>HTTP Request : Deflate triggers "Unexpected end of ZLIB input stream". Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
</ul>
<h3>Other Samplers</h3>