Skip to content

Commit 8f53178

Browse files
author
Stephane Landelle
committed
Have one MaxRedirectException instance per Protocol instance
1 parent 3f9eae9 commit 8f53178

File tree

2 files changed

+8
-2
lines changed
  • providers
    • netty3/src/main/java/org/asynchttpclient/providers/netty3/handler
    • netty4/src/main/java/org/asynchttpclient/providers/netty4/handler

2 files changed

+8
-2
lines changed

providers/netty3/src/main/java/org/asynchttpclient/providers/netty3/handler/Protocol.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public abstract class Protocol {
7373
private final boolean hasResponseFilters;
7474
protected final boolean hasIOExceptionFilters;
7575
private final TimeConverter timeConverter;
76+
private final MaxRedirectException maxRedirectException;
7677

7778
public static final Set<Integer> REDIRECT_STATUSES = new HashSet<Integer>();
7879
static {
@@ -102,6 +103,8 @@ public Protocol(ChannelManager channelManager, AsyncHttpClientConfig config, Net
102103
hasResponseFilters = !config.getResponseFilters().isEmpty();
103104
hasIOExceptionFilters = !config.getIOExceptionFilters().isEmpty();
104105
timeConverter = config.getTimeConverter();
106+
maxRedirectException = new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects());
107+
maxRedirectException.setStackTrace(new StackTraceElement[0]);
105108
}
106109

107110
public abstract void handle(Channel channel, NettyResponseFuture<?> future, Object message) throws Exception;
@@ -130,7 +133,7 @@ protected boolean exitAfterHandlingRedirect(//
130133

131134
if (followRedirect(config, request) && REDIRECT_STATUSES.contains(statusCode)) {
132135
if (future.incrementAndGetCurrentRedirectCount() >= config.getMaxRedirects()) {
133-
throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects());
136+
throw maxRedirectException;
134137

135138
} else {
136139
// We must allow 401 handling again.

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/handler/Protocol.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public abstract class Protocol {
7373
private final boolean hasResponseFilters;
7474
protected final boolean hasIOExceptionFilters;
7575
private final TimeConverter timeConverter;
76+
private final MaxRedirectException maxRedirectException;
7677

7778
public static final Set<Integer> REDIRECT_STATUSES = new HashSet<Integer>();
7879
static {
@@ -102,6 +103,8 @@ public Protocol(ChannelManager channelManager, AsyncHttpClientConfig config, Net
102103
hasResponseFilters = !config.getResponseFilters().isEmpty();
103104
hasIOExceptionFilters = !config.getIOExceptionFilters().isEmpty();
104105
timeConverter = config.getTimeConverter();
106+
maxRedirectException = new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects());
107+
maxRedirectException.setStackTrace(new StackTraceElement[0]);
105108
}
106109

107110
public abstract void handle(Channel channel, NettyResponseFuture<?> future, Object message) throws Exception;
@@ -130,7 +133,7 @@ protected boolean exitAfterHandlingRedirect(//
130133

131134
if (followRedirect(config, request) && REDIRECT_STATUSES.contains(statusCode)) {
132135
if (future.incrementAndGetCurrentRedirectCount() >= config.getMaxRedirects()) {
133-
throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects());
136+
throw maxRedirectException;
134137

135138
} else {
136139
// We must allow 401 handling again.

0 commit comments

Comments
 (0)