Skip to content

Commit 6aeecd1

Browse files
Merge branch 'main' into add_token_pagination
2 parents 6d93904 + 3ff49b8 commit 6aeecd1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/com/twilio/http/HttpClient.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
1313
import org.apache.hc.client5.http.config.RequestConfig;
1414
import org.apache.hc.client5.http.impl.DefaultRedirectStrategy;
15+
import org.apache.hc.core5.http.protocol.HttpContext;
1516
import org.apache.hc.client5.http.protocol.RedirectStrategy;
1617
import org.apache.hc.core5.http.ContentType;
18+
import org.apache.hc.core5.http.HttpRequest;
19+
import org.apache.hc.core5.http.HttpResponse;
20+
import org.apache.hc.core5.http.ProtocolException;
1721
import org.apache.hc.core5.http.io.SocketConfig;
1822
import org.apache.hc.core5.util.Timeout;
1923

@@ -57,10 +61,21 @@ public abstract class HttpClient {
5761
public static final int RETRIES = 3;
5862
public static final long DELAY_MILLIS = 100L;
5963

64+
/**
65+
* Custom redirect strategy that disables automatic redirects.
66+
*/
67+
private static class TwilioRedirectStrategy extends DefaultRedirectStrategy {
68+
@Override
69+
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
70+
// Disable all automatic redirects
71+
return false;
72+
}
73+
}
74+
6075
// Default redirect strategy to not auto-redirect for any methods (empty string array).
6176
@Getter
6277
@Setter
63-
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
78+
private RedirectStrategy redirectStrategy = new TwilioRedirectStrategy();
6479

6580
@Getter
6681
private Response lastResponse;

0 commit comments

Comments
 (0)