Skip to content

Commit

Permalink
fix #553 Remove the deprecated HttpClient#chunkedTransfer
Browse files Browse the repository at this point in the history
By default Transfer-Encoding: chunked will be applied for those HTTP methods
for which a request body is expected. If the user wants to disable that setting
then the user can provide Content-Length via request headers and
thus Transfer-Encoding will be removed.
  • Loading branch information
violetagg committed Feb 27, 2019
1 parent 366f301 commit 34e644c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 53 deletions.
28 changes: 3 additions & 25 deletions src/main/java/reactor/netty/http/client/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
* is called to retrieve a ready to use {@link TcpClient}, then {@link
* TcpClient#configure()} retrieve a usable {@link Bootstrap} for the final {@link
* TcpClient#connect()} is called.
* {@code Transfer-Encoding: chunked} will be applied for those HTTP methods for which
* a request body is expected. {@code Content-Length} provided via request headers
* will disable {@code Transfer-Encoding: chunked}.
* <p> Examples:
* <pre>
* {@code
Expand Down Expand Up @@ -411,25 +414,6 @@ public final HttpClient mapConnect(BiFunction<? super Mono<? extends Connection>
return new HttpClientOnConnectMap(this, connector);
}

/**
* Specifies whether transfer-encoding is enabled
*
* @param chunkedEnabled if true transfer-encoding is enabled otherwise disabled.
* (default: true)
* @return a new {@link HttpClient}
* @deprecated Using {@link #headers(Consumer)} for specifying the content length
* will disable the transfer-encoding
*/
@Deprecated
public final HttpClient chunkedTransfer(boolean chunkedEnabled) {
if (chunkedEnabled) {
return tcpConfiguration(CHUNKED_ATTR_CONFIG);
}
else {
return tcpConfiguration(CHUNKED_ATTR_DISABLE);
}
}

/**
* Apply cookies configuration.
*
Expand Down Expand Up @@ -915,18 +899,12 @@ static String reactorNettyVersion() {
static final Function<TcpClient, TcpClient> COMPRESS_ATTR_DISABLE =
tcp -> tcp.bootstrap(HttpClientConfiguration.MAP_NO_COMPRESS);

static final Function<TcpClient, TcpClient> CHUNKED_ATTR_CONFIG =
tcp -> tcp.bootstrap(HttpClientConfiguration.MAP_CHUNKED);

static final Function<TcpClient, TcpClient> KEEPALIVE_ATTR_CONFIG =
tcp -> tcp.bootstrap(HttpClientConfiguration.MAP_KEEPALIVE);

static final Function<TcpClient, TcpClient> KEEPALIVE_ATTR_DISABLE =
tcp -> tcp.bootstrap(HttpClientConfiguration.MAP_NO_KEEPALIVE);

static final Function<TcpClient, TcpClient> CHUNKED_ATTR_DISABLE =
tcp -> tcp.bootstrap(HttpClientConfiguration.MAP_NO_CHUNKED);

static final Function<TcpClient, TcpClient> FOLLOW_REDIRECT_ATTR_CONFIG =
tcp -> tcp.bootstrap(HttpClientConfiguration.MAP_REDIRECT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ final class HttpClientConfiguration {
AttributeKey.newInstance("httpClientConf");

boolean acceptGzip = false;
Boolean chunkedTransfer = null;
String uri = null;
String baseUrl = null;
HttpHeaders headers = null;
Expand Down Expand Up @@ -75,7 +74,6 @@ final class HttpClientConfiguration {
this.cookieEncoder = from.cookieEncoder;
this.cookieDecoder = from.cookieDecoder;
this.followRedirectPredicate = from.followRedirectPredicate;
this.chunkedTransfer = from.chunkedTransfer;
this.baseUrl = from.baseUrl;
this.headers = from.headers;
this.method = from.method;
Expand All @@ -96,7 +94,6 @@ static HttpClientConfiguration getAndClean(Bootstrap b) {
return hcc;
}

@SuppressWarnings("unchecked")
static HttpClientConfiguration getOrCreate(Bootstrap b) {

HttpClientConfiguration hcc = (HttpClientConfiguration) b.config()
Expand All @@ -111,7 +108,6 @@ static HttpClientConfiguration getOrCreate(Bootstrap b) {
return hcc;
}

@SuppressWarnings("unchecked")
static HttpClientConfiguration get(Bootstrap b) {

HttpClientConfiguration hcc = (HttpClientConfiguration) b.config()
Expand Down Expand Up @@ -157,17 +153,6 @@ static HttpClientConfiguration get(Bootstrap b) {
return b;
};

static final Function<Bootstrap, Bootstrap> MAP_CHUNKED = b -> {
getOrCreate(b).chunkedTransfer = true;
return b;
};


static final Function<Bootstrap, Bootstrap> MAP_NO_CHUNKED = b -> {
getOrCreate(b).chunkedTransfer = false;
return b;
};


static final Pattern FOLLOW_REDIRECT_CODES = Pattern.compile("30[1278]");
static final BiPredicate<HttpClientRequest, HttpClientResponse> FOLLOW_REDIRECT_PREDICATE =
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/reactor/netty/http/client/HttpClientConnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ static final class HttpClientHandler extends SocketAddress
final BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>>
handler;
final boolean compress;
final Boolean chunkedTransfer;
final UriEndpointFactory uriEndpointFactory;
final String websocketProtocols;
final int maxFramePayloadLength;
Expand All @@ -457,7 +456,6 @@ static final class HttpClientHandler extends SocketAddress
this.method = configuration.method;
this.compress = configuration.acceptGzip;
this.followRedirectPredicate = configuration.followRedirectPredicate;
this.chunkedTransfer = configuration.chunkedTransfer;
this.cookieEncoder = configuration.cookieEncoder;
this.cookieDecoder = configuration.cookieDecoder;
this.proxyProvider = proxyProvider;
Expand Down Expand Up @@ -547,17 +545,14 @@ Publisher<Void> requestWithBody(HttpClientOperations ch) {

ch.followRedirectPredicate(followRedirectPredicate);

if (chunkedTransfer == null) {
if (Objects.equals(method, HttpMethod.GET) ||
Objects.equals(method, HttpMethod.HEAD) ||
Objects.equals(method, HttpMethod.DELETE)) {
ch.chunkedTransfer(false);
} else if (!headers.contains(HttpHeaderNames.CONTENT_LENGTH)) {
ch.chunkedTransfer(true);
}
}
else {
ch.chunkedTransfer(chunkedTransfer);
if (Objects.equals(method, HttpMethod.GET) ||
Objects.equals(method, HttpMethod.HEAD) ||
Objects.equals(method, HttpMethod.DELETE)) {
ch.chunkedTransfer(false);
} else if (headers.contains(HttpHeaderNames.CONTENT_LENGTH)) {
ch.chunkedTransfer(false);
} else {
ch.chunkedTransfer(true);
}

if (handler != null) {
Expand Down

0 comments on commit 34e644c

Please sign in to comment.