Upgrade HttpCore to version 5.0-beta7

This commit is contained in:
Ryan Schmitt 2019-01-29 15:09:55 -08:00
parent 972f0158ec
commit f8653a011a
32 changed files with 107 additions and 96 deletions

View File

@ -234,7 +234,7 @@ public class HttpTestUtils {
* @return an {@link HttpEntity}
*/
public static HttpEntity makeBody(final int nbytes) {
return new ByteArrayEntity(getRandomBytes(nbytes));
return new ByteArrayEntity(getRandomBytes(nbytes), null);
}
public static HttpCacheEntry makeCacheEntry(final Date requestDate, final Date responseDate) {

View File

@ -357,7 +357,7 @@ public class TestCachingExec extends TestCachingExecChain {
}
return 'y';
}
}, -1));
}, -1, null));
final ClassicHttpResponse resp = mockExecChain.proceed(
isA(ClassicHttpRequest.class), isA(ExecChain.Scope.class));

View File

@ -1219,7 +1219,7 @@ public abstract class TestCachingExecChain {
}
throw new SocketTimeoutException("Read timed out");
}
}, 128));
}, 128, null));
resp1.setHeader("Date", DateUtils.formatDate(now));
backendExpectsAnyRequestAndReturn(resp1);

View File

@ -146,7 +146,7 @@ public class TestProtocolDeviations {
private HttpEntity makeBody(final int nbytes) {
final byte[] bytes = new byte[nbytes];
new Random().nextBytes(bytes);
return new ByteArrayEntity(bytes);
return new ByteArrayEntity(bytes, null);
}
public static HttpRequest eqRequest(final HttpRequest in) {

View File

@ -50,8 +50,8 @@ import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.io.entity.BasicHttpEntity;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
import org.apache.hc.core5.http.message.BasicHeader;
@ -574,7 +574,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
final BasicClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
post.setHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
post.setHeader("Content-Length", "128");
post.setEntity(new BasicHttpEntity());
post.setEntity(new StringEntity("whatever"));
final Capture<ClassicHttpRequest> reqCap = EasyMock.newCapture();
@ -613,7 +613,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
public void testRequestsNotExpecting100ContinueBehaviorShouldNotSetExpectContinueHeader() throws Exception {
final BasicClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
post.setHeader("Content-Length", "128");
post.setEntity(new BasicHttpEntity());
post.setEntity(new StringEntity("whatever"));
final Capture<ClassicHttpRequest> reqCap = EasyMock.newCapture();
@ -1382,7 +1382,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
for (int i = 0; i < bytes1.length; i++) {
bytes1[i] = (byte) 1;
}
resp1.setEntity(new ByteArrayEntity(bytes1));
resp1.setEntity(new ByteArrayEntity(bytes1, null));
final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
req2.setHeader("Cache-Control", "no-cache");
@ -1399,7 +1399,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
for (int i = 0; i < bytes2.length; i++) {
bytes2[i] = (byte) 2;
}
resp2.setEntity(new ByteArrayEntity(bytes2));
resp2.setEntity(new ByteArrayEntity(bytes2, null));
final Date inTwoSeconds = new Date(now.getTime() + 2000L);
final ClassicHttpRequest req3 = new BasicClassicHttpRequest("GET", "/");
@ -1411,7 +1411,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
for (int i = 0; i < bytes3.length; i++) {
bytes3[i] = (byte) 2;
}
resp3.setEntity(new ByteArrayEntity(bytes3));
resp3.setEntity(new ByteArrayEntity(bytes3, null));
EasyMock.expect(
mockExecChain.proceed(
@ -1463,7 +1463,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
for (int i = 0; i < bytes1.length; i++) {
bytes1[i] = (byte) 1;
}
resp1.setEntity(new ByteArrayEntity(bytes1));
resp1.setEntity(new ByteArrayEntity(bytes1, null));
final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
req2.setHeader("Cache-Control", "no-cache");
@ -1480,7 +1480,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
for (int i = 0; i < bytes2.length; i++) {
bytes2[i] = (byte) 2;
}
resp2.setEntity(new ByteArrayEntity(bytes2));
resp2.setEntity(new ByteArrayEntity(bytes2, null));
final Date inTwoSeconds = new Date(now.getTime() + 2000L);
final ClassicHttpRequest req3 = new BasicClassicHttpRequest("GET", "/");
@ -1492,7 +1492,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
for (int i = 0; i < bytes3.length; i++) {
bytes3[i] = (byte) 2;
}
resp3.setEntity(new ByteArrayEntity(bytes3));
resp3.setEntity(new ByteArrayEntity(bytes3, null));
EasyMock.expect(
mockExecChain.proceed(
@ -1550,7 +1550,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
originResponse.setHeader("Cache-Control", "max-age=3600");
final byte[] bytes = new byte[51];
new Random().nextBytes(bytes);
originResponse.setEntity(new ByteArrayEntity(bytes));
originResponse.setEntity(new ByteArrayEntity(bytes, null));
EasyMock.expect(
mockExecChain.proceed(
@ -2529,7 +2529,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
validated.setHeader("Cache-Control", "public");
validated.setHeader("Last-Modified", DateUtils.formatDate(oneYearAgo));
validated.setHeader("Content-Length", "128");
validated.setEntity(new ByteArrayEntity(bytes));
validated.setEntity(new ByteArrayEntity(bytes, null));
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry();

View File

@ -134,7 +134,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
final byte[] body101 = HttpTestUtils.getRandomBytes(101);
final ByteArrayInputStream buf = new ByteArrayInputStream(body101);
final ConsumableInputStream cis = new ConsumableInputStream(buf);
final HttpEntity entity = new InputStreamEntity(cis, 101);
final HttpEntity entity = new InputStreamEntity(cis, 101, null);
resp2.setEntity(entity);
backendExpectsAnyRequestAndReturn(resp2);

View File

@ -29,6 +29,7 @@ package org.apache.hc.client5.http.fluent;
import java.io.IOException;
import org.apache.hc.client5.http.impl.classic.AbstractHttpClientResponseHandler;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
@ -46,7 +47,7 @@ public class ContentResponseHandler extends AbstractHttpClientResponseHandler<Co
@Override
public Content handleEntity(final HttpEntity entity) throws IOException {
return entity != null ?
new Content(EntityUtils.toByteArray(entity), EntityUtils.getContentTypeOrDefault(entity)) :
new Content(EntityUtils.toByteArray(entity), ContentType.parse(entity.getContentType())) :
Content.NO_CONTENT;
}

View File

@ -347,7 +347,7 @@ public class Request {
}
public Request bodyByteArray(final byte[] b) {
return body(new ByteArrayEntity(b));
return body(new ByteArrayEntity(b, null));
}
/**
@ -358,7 +358,7 @@ public class Request {
}
public Request bodyByteArray(final byte[] b, final int off, final int len) {
return body(new ByteArrayEntity(b, off, len));
return body(new ByteArrayEntity(b, off, len, null));
}
/**

View File

@ -111,9 +111,7 @@ public class Response {
final HttpEntity entity = this.response.getEntity();
if (entity != null) {
final ByteArrayEntity byteArrayEntity = new ByteArrayEntity(
EntityUtils.toByteArray(entity));
final ContentType contentType = EntityUtils.getContentTypeOrDefault(entity);
byteArrayEntity.setContentType(contentType.toString());
EntityUtils.toByteArray(entity), ContentType.parse(entity.getContentType()));
this.response.setEntity(byteArrayEntity);
}
return this.response;

View File

@ -164,7 +164,7 @@ public class AsyncRandomHandler implements AsyncServerExchangeHandler {
private final ByteBuffer buffer;
public RandomBinAsyncEntityProducer(final long len) {
super(2048, 512, ContentType.DEFAULT_TEXT);
super(512, ContentType.DEFAULT_TEXT);
length = len;
remaining = len;
buffer = ByteBuffer.allocate(1024);
@ -186,7 +186,7 @@ public class AsyncRandomHandler implements AsyncServerExchangeHandler {
}
@Override
public int available() {
public int availableData() {
return Integer.MAX_VALUE;
}

View File

@ -32,6 +32,7 @@ import java.util.Locale;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpStatus;
@ -76,16 +77,17 @@ public class EchoHandler implements HttpRequestHandler {
// For some reason, just putting the incoming entity into
// the response will not work. We have to buffer the message.
final byte[] data;
final ContentType contentType;
if (entity == null) {
data = new byte [0];
contentType = null;
} else {
data = EntityUtils.toByteArray(entity);
final String contentTypeStr = entity.getContentType();
contentType = contentTypeStr == null ? null : ContentType.parse(contentTypeStr);
}
final ByteArrayEntity bae = new ByteArrayEntity(data);
if (entity != null) {
bae.setContentType(entity.getContentType());
}
final ByteArrayEntity bae = new ByteArrayEntity(data, contentType);
entity = bae;
response.setCode(HttpStatus.SC_OK);

View File

@ -36,6 +36,7 @@ import java.nio.charset.StandardCharsets;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.MethodNotSupportedException;
@ -47,7 +48,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
/**
* A handler that generates random data.
*/
public class RandomHandler implements HttpRequestHandler {
public class RandomHandler implements HttpRequestHandler {
/**
* Handles a request by generating random data.
@ -127,6 +128,7 @@ public class RandomHandler implements HttpRequestHandler {
* 0 to maxint
*/
public RandomEntity(final long len) {
super((ContentType) null, null);
length = len;
}

View File

@ -75,7 +75,8 @@ public class TestFluent extends LocalServerTestBase {
HttpEntity responseEntity = null;
final HttpEntity requestEntity = request.getEntity();
if (requestEntity != null) {
final ContentType contentType = EntityUtils.getContentTypeOrDefault(requestEntity);
final String contentTypeStr = requestEntity.getContentType();
final ContentType contentType = contentTypeStr == null ? ContentType.DEFAULT_TEXT : ContentType.parse(contentTypeStr);
if (ContentType.TEXT_PLAIN.getMimeType().equals(contentType.getMimeType())) {
responseEntity = new StringEntity(
EntityUtils.toString(requestEntity), ContentType.TEXT_PLAIN);

View File

@ -202,7 +202,7 @@ public class TestClientAuthentication extends LocalServerTestBase {
httpput.setEntity(new InputStreamEntity(
new ByteArrayInputStream(
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
-1));
-1, null));
final HttpClientContext context = HttpClientContext.create();
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test".toCharArray()));
@ -225,7 +225,7 @@ public class TestClientAuthentication extends LocalServerTestBase {
httpput.setEntity(new InputStreamEntity(
new ByteArrayInputStream(
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
-1));
-1, null));
final HttpClientContext context = HttpClientContext.create();
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
@ -270,7 +270,7 @@ public class TestClientAuthentication extends LocalServerTestBase {
final HttpPost httppost = new HttpPost("/");
httppost.setEntity(new InputStreamEntity(
new ByteArrayInputStream(
new byte[] { 0,1,2,3,4,5,6,7,8,9 }), -1));
new byte[] { 0,1,2,3,4,5,6,7,8,9 }), -1, null));
final HttpClientContext context = HttpClientContext.create();
context.setRequestConfig(RequestConfig.custom()

View File

@ -189,7 +189,7 @@ public class TestClientRequestExecution extends LocalServerTestBase {
httppost.setEntity(new InputStreamEntity(
new ByteArrayInputStream(
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
-1));
-1, null));
this.httpclient.execute(target, httppost, context);
}

View File

@ -313,7 +313,7 @@ public class TestContentCodings extends LocalServerTestBase {
final byte[] compressed = new byte[compressedLength];
System.arraycopy(output, 0, compressed, 0, compressedLength);
response.setEntity(new InputStreamEntity(
new ByteArrayInputStream(compressed), compressedLength));
new ByteArrayInputStream(compressed), compressedLength, null));
return;
}
}
@ -374,7 +374,7 @@ public class TestContentCodings extends LocalServerTestBase {
final byte[] arr = bytes.toByteArray();
response.setEntity(new InputStreamEntity(new ByteArrayInputStream(arr),
arr.length));
arr.length, null));
return;
}

View File

@ -286,18 +286,20 @@ public class RequestBuilder {
entity = null;
final HttpEntity originalEntity = request.getEntity();
final ContentType contentType = EntityUtils.getContentType(originalEntity);
if (contentType != null &&
if (originalEntity != null) {
final ContentType contentType = ContentType.parse(originalEntity.getContentType());
if (contentType != null &&
contentType.getMimeType().equals(ContentType.APPLICATION_FORM_URLENCODED.getMimeType())) {
try {
final List<NameValuePair> formParams = EntityUtils.parse(originalEntity);
if (!formParams.isEmpty()) {
parameters = formParams;
try {
final List<NameValuePair> formParams = EntityUtils.parse(originalEntity);
if (!formParams.isEmpty()) {
parameters = formParams;
}
} catch (final IOException ignore) {
}
} catch (final IOException ignore) {
} else {
entity = originalEntity;
}
} else {
entity = originalEntity;
}
try {

View File

@ -37,7 +37,6 @@ import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
import org.apache.hc.core5.http.io.entity.BasicHttpEntity;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.apache.hc.core5.http.io.entity.FileEntity;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;
@ -311,27 +310,24 @@ public class EntityBuilder {
public HttpEntity build() {
final AbstractHttpEntity e;
if (this.text != null) {
e = new StringEntity(this.text, getContentOrDefault(ContentType.DEFAULT_TEXT));
e = new StringEntity(this.text, getContentOrDefault(ContentType.DEFAULT_TEXT), this.contentEncoding,
this.chunked);
} else if (this.binary != null) {
e = new ByteArrayEntity(this.binary, getContentOrDefault(ContentType.DEFAULT_BINARY));
e = new ByteArrayEntity(this.binary, getContentOrDefault(ContentType.DEFAULT_BINARY),
this.contentEncoding, this.chunked);
} else if (this.stream != null) {
e = new InputStreamEntity(this.stream, -1, getContentOrDefault(ContentType.DEFAULT_BINARY));
e = new InputStreamEntity(this.stream, -1, getContentOrDefault(ContentType.DEFAULT_BINARY),
this.contentEncoding);
} else if (this.parameters != null) {
e = new UrlEncodedFormEntity(this.parameters,
this.contentType != null ? this.contentType.getCharset() : null);
} else if (this.serializable != null) {
e = new SerializableEntity(this.serializable);
e.setContentType(ContentType.DEFAULT_BINARY.toString());
e = new SerializableEntity(this.serializable, ContentType.DEFAULT_BINARY, this.contentEncoding);
} else if (this.file != null) {
e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY));
e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY), this.contentEncoding);
} else {
e = new BasicHttpEntity();
throw new IllegalStateException("No entity set");
}
if (e.getContentType() != null && this.contentType != null) {
e.setContentType(this.contentType.toString());
}
e.setContentEncoding(this.contentEncoding);
e.setChunked(this.chunked);
if (this.gzipCompress) {
return new GzipCompressingEntity(e);
}

View File

@ -170,7 +170,8 @@ class InternalHttp2AsyncExecRuntime implements AsyncExecRuntime {
final HttpHost target = endpoint.target;
final RequestConfig requestConfig = context.getRequestConfig();
final Timeout connectTimeout = requestConfig.getConnectTimeout();
return Operations.cancellable(connPool.getSession(target, connectTimeout, new FutureCallback<IOSession>() {
return Operations.cancellable(connPool.getSession(target, connectTimeout,
new FutureCallback<IOSession>() {
@Override
public void completed(final IOSession ioSession) {

View File

@ -75,6 +75,11 @@ class LoggingIOSession implements ProtocolIOSession {
return session.getId();
}
@Override
public Lock getLock() {
return this.session.getLock();
}
@Override
public Lock lock() {
return this.session.lock();
@ -233,8 +238,9 @@ class LoggingIOSession implements ProtocolIOSession {
final NamedEndpoint endpoint,
final SSLBufferMode sslBufferMode,
final SSLSessionInitializer initializer,
final SSLSessionVerifier verifier) throws UnsupportedOperationException {
session.startTls(sslContext, endpoint, sslBufferMode, initializer, verifier);
final SSLSessionVerifier verifier,
final Timeout handshakeTimeout) throws UnsupportedOperationException {
session.startTls(sslContext, endpoint, sslBufferMode, initializer, verifier, handshakeTimeout);
}
@Override

View File

@ -156,7 +156,8 @@ public final class MinimalHttp2AsyncClient extends AbstractMinimalHttpAsyncClien
final Timeout connectTimeout = requestConfig.getConnectTimeout();
final HttpHost target = new HttpHost(request.getScheme(), request.getAuthority());
final Future<IOSession> sessionFuture = connPool.getSession(target, connectTimeout, new FutureCallback<IOSession>() {
final Future<IOSession> sessionFuture = connPool.getSession(target, connectTimeout,
new FutureCallback<IOSession>() {
@Override
public void completed(final IOSession session) {

View File

@ -95,7 +95,8 @@ final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectio
host,
session.getLocalAddress(),
session.getRemoteAddress(),
attachment);
attachment,
connectTimeout);
}
future.completed(connection);
}
@ -124,7 +125,8 @@ final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectio
host,
connection.getLocalAddress(),
connection.getRemoteAddress(),
attachment);
attachment,
null);
}
}

View File

@ -149,12 +149,14 @@ final class DefaultManagedAsyncClientConnection implements ManagedAsyncClientCon
final NamedEndpoint endpoint,
final SSLBufferMode sslBufferMode,
final SSLSessionInitializer initializer,
final SSLSessionVerifier verifier) throws UnsupportedOperationException {
final SSLSessionVerifier verifier,
final Timeout handshakeTimeout) throws UnsupportedOperationException {
if (log.isDebugEnabled()) {
log.debug(getId() + ": start TLS");
}
if (ioSession instanceof TransportSecurityLayer) {
((TransportSecurityLayer) ioSession).startTls(sslContext, endpoint, sslBufferMode, initializer, verifier);
((TransportSecurityLayer) ioSession).startTls(sslContext, endpoint, sslBufferMode, initializer, verifier,
handshakeTimeout);
} else {
throw new UnsupportedOperationException("TLS upgrade not supported");
}

View File

@ -50,6 +50,7 @@ import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -86,7 +87,8 @@ abstract class AbstractClientTlsStrategy implements TlsStrategy {
final HttpHost host,
final SocketAddress localAddress,
final SocketAddress remoteAddress,
final Object attachment) {
final Object attachment,
final Timeout handshakeTimeout) {
tlsSession.startTls(sslContext, host, sslBufferManagement, new SSLSessionInitializer() {
@Override
@ -129,7 +131,7 @@ abstract class AbstractClientTlsStrategy implements TlsStrategy {
return createTlsDetails(sslEngine);
}
});
}, handshakeTimeout);
return true;
}

View File

@ -41,7 +41,6 @@ import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.io.entity.BasicHttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.message.BasicHeader;
@ -69,7 +68,7 @@ public class TestRequestBuilder {
@Test
public void testBasicWithEntity() throws Exception {
final HttpEntity entity = new BasicHttpEntity();
final HttpEntity entity = new StringEntity("whatever");
final ClassicHttpRequest request = RequestBuilder.post().setEntity(entity).build();
Assert.assertNotNull(request);
Assert.assertEquals("POST", request.getMethod());
@ -79,7 +78,7 @@ public class TestRequestBuilder {
@Test
public void testGetWithEntity() throws Exception {
final HttpEntity entity = new BasicHttpEntity();
final HttpEntity entity = new StringEntity("whatever");
final ClassicHttpRequest request = RequestBuilder.get().setEntity(entity).build();
Assert.assertNotNull(request);
Assert.assertEquals("GET", request.getMethod());
@ -156,7 +155,7 @@ public class TestRequestBuilder {
@Test
public void testCopyWithQueryParams() throws Exception {
final HttpGet get = new HttpGet("/stuff?p1=this&p2=that");
final RequestBuilder builder = RequestBuilder.copy(get);
final RequestBuilder builder = RequestBuilder.copy(get).setEntity(new StringEntity(""));
final List<NameValuePair> parameters = builder.getParameters();
Assert.assertNotNull(parameters);
Assert.assertEquals(0, parameters.size());

View File

@ -36,6 +36,7 @@ import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;
@ -63,7 +64,7 @@ public class TestDecompressingEntity {
public void testStreaming() throws Exception {
final CRC32 crc32 = new CRC32();
final ByteArrayInputStream in = new ByteArrayInputStream("1234567890".getBytes(StandardCharsets.US_ASCII));
final InputStreamEntity wrapped = new InputStreamEntity(in, -1);
final InputStreamEntity wrapped = new InputStreamEntity(in, -1, ContentType.DEFAULT_TEXT);
final ChecksumEntity entity = new ChecksumEntity(wrapped, crc32);
Assert.assertTrue(entity.isStreaming());
final String s = EntityUtils.toString(entity);

View File

@ -30,6 +30,7 @@ package org.apache.hc.client5.http.entity;
import java.nio.charset.StandardCharsets;
import java.util.zip.Deflater;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
@ -51,7 +52,7 @@ public class TestDeflate {
compresser.finish();
final int len = compresser.deflate(compressed);
final HttpEntity entity = new DeflateDecompressingEntity(new ByteArrayEntity(compressed, 0, len));
final HttpEntity entity = new DeflateDecompressingEntity(new ByteArrayEntity(compressed, 0, len, ContentType.APPLICATION_OCTET_STREAM));
Assert.assertEquals(s, EntityUtils.toString(entity));
}

View File

@ -49,8 +49,7 @@ public class TestGZip {
@Test
public void testBasic() throws Exception {
final String s = "some kind of text";
final StringEntity e = new StringEntity(s, ContentType.TEXT_PLAIN);
e.setChunked(false);
final StringEntity e = new StringEntity(s, ContentType.TEXT_PLAIN, false);
final GzipCompressingEntity gzipe = new GzipCompressingEntity(e);
Assert.assertTrue(gzipe.isChunked());
Assert.assertEquals(-1, gzipe.getContentLength());
@ -64,7 +63,7 @@ public class TestGZip {
final GzipCompressingEntity gzipe = new GzipCompressingEntity(in);
final ByteArrayOutputStream buf = new ByteArrayOutputStream();
gzipe.writeTo(buf);
final ByteArrayEntity out = new ByteArrayEntity(buf.toByteArray());
final ByteArrayEntity out = new ByteArrayEntity(buf.toByteArray(), ContentType.APPLICATION_OCTET_STREAM);
final GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(out);
Assert.assertEquals("some kind of text", EntityUtils.toString(gunzipe, StandardCharsets.US_ASCII));
}
@ -96,7 +95,7 @@ public class TestGZip {
bytes[i] = (byte) (data[i] & 0xff);
}
try (final GzipDecompressingEntity entity = new GzipDecompressingEntity(new InputStreamEntity(new ByteArrayInputStream(bytes)))) {
try (final GzipDecompressingEntity entity = new GzipDecompressingEntity(new InputStreamEntity(new ByteArrayInputStream(bytes), ContentType.APPLICATION_OCTET_STREAM))) {
Assert.assertEquals("stream-1\nstream-2\n", EntityUtils.toString(entity, StandardCharsets.US_ASCII));
}
}

View File

@ -46,6 +46,7 @@ import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.MalformedChallengeException;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
@ -641,7 +642,7 @@ public class TestDigestScheme {
@Test
public void testDigestAuthenticationQopAuthOrAuthIntNonRepeatableEntity() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest("Post", "/");
request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1, ContentType.DEFAULT_TEXT));
final HttpHost host = new HttpHost("somehost", 80);
final AuthScope authScope = new AuthScope(host, "realm1", null);
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
@ -690,7 +691,7 @@ public class TestDigestScheme {
@Test(expected=AuthenticationException.class)
public void testDigestAuthenticationQopIntOnlyNonRepeatableEntity() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest("Post", "/");
request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1, ContentType.DEFAULT_TEXT));
final HttpHost host = new HttpHost("somehost", 80);
final AuthScope authScope = new AuthScope(host, "realm1", null);
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();

View File

@ -32,6 +32,7 @@ import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecRuntime;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.DecompressingEntity;
import org.apache.hc.client5.http.entity.EntityBuilder;
import org.apache.hc.client5.http.entity.GzipDecompressingEntity;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.ClassicHttpRequest;
@ -107,8 +108,7 @@ public class TestContentCompressionExec {
public void testGzipContentEncoding() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
final StringEntity original = new StringEntity("encoded stuff");
original.setContentEncoding("GZip");
final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("GZip").build();
response.setEntity(original);
Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
@ -124,8 +124,7 @@ public class TestContentCompressionExec {
public void testGzipContentEncodingZeroLength() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
final StringEntity original = new StringEntity("");
original.setContentEncoding("GZip");
final HttpEntity original = EntityBuilder.create().setText("").setContentEncoding("GZip").build();
response.setEntity(original);
Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
@ -141,8 +140,7 @@ public class TestContentCompressionExec {
public void testXGzipContentEncoding() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
final StringEntity original = new StringEntity("encoded stuff");
original.setContentEncoding("x-gzip");
final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("x-gzip").build();
response.setEntity(original);
Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
@ -158,8 +156,7 @@ public class TestContentCompressionExec {
public void testDeflateContentEncoding() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
final StringEntity original = new StringEntity("encoded stuff");
original.setContentEncoding("deFlaTe");
final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("deFlaTe").build();
response.setEntity(original);
Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
@ -175,8 +172,7 @@ public class TestContentCompressionExec {
public void testIdentityContentEncoding() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
final StringEntity original = new StringEntity("encoded stuff");
original.setContentEncoding("identity");
final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("identity").build();
response.setEntity(original);
Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
@ -192,8 +188,7 @@ public class TestContentCompressionExec {
public void testUnknownContentEncoding() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
final StringEntity original = new StringEntity("encoded stuff");
original.setContentEncoding("whatever");
final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("whatever").build();
response.setEntity(original);
impl = new ContentCompressionExec(false);
@ -207,8 +202,7 @@ public class TestContentCompressionExec {
public void testContentEncodingRequestParameter() throws Exception {
final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
final StringEntity original = new StringEntity("encoded stuff");
original.setContentEncoding("GZip");
final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("GZip").build();
response.setEntity(original);
final RequestConfig config = RequestConfig.custom()

View File

@ -120,7 +120,7 @@ public class TestURIUtils {
Assert.assertEquals("http://a/b/c/g", URIUtils.resolve(this.baseURI, "./g").toString());
Assert.assertEquals("http://a/b/c/g/", URIUtils.resolve(this.baseURI, "g/").toString());
Assert.assertEquals("http://a/g", URIUtils.resolve(this.baseURI, "/g").toString());
Assert.assertEquals("http://g/", URIUtils.resolve(this.baseURI, "//g").toString());
Assert.assertEquals("http://g", URIUtils.resolve(this.baseURI, "//g").toString());
Assert.assertEquals("http://a/b/c/d;p?y", URIUtils.resolve(this.baseURI, "?y").toString());
Assert.assertEquals("http://a/b/c/d;p?y#f", URIUtils.resolve(this.baseURI, "?y#f")
.toString());

View File

@ -67,7 +67,7 @@
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<httpcore.version>5.0-beta6</httpcore.version>
<httpcore.version>5.0-beta7</httpcore.version>
<log4j.version>2.9.1</log4j.version>
<commons-codec.version>1.12</commons-codec.version>
<conscrypt.version>1.4.1</conscrypt.version>