Java 11 HttpClient not handling redirects properly when using custom SSLContext
I'm working on a project and hit a roadblock. Quick question that's been bugging me - I'm working on a Java application using the HttpClient introduced in Java 11, and I've encountered a question with handling HTTP redirects... My application needs to connect to a server that requires a custom SSLContext due to self-signed certificates. However, when a redirect occurs, it seems that the client does not follow the redirect properly, and I get a `java.net.ProtocolException: Server redirected too many times`. I've set the `followRedirects` method to `true`, but the scenario continues. Here's how I configured the HttpClient: ```java SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { new X509TrustManager() { public void checkClientTrusted(X509Certificate[] certs, String authType) {} public void checkServerTrusted(X509Certificate[] certs, String authType) {} public X509Certificate[] getAcceptedIssuers() { return null; } } }, new SecureRandom()); HttpClient httpClient = HttpClient.newBuilder() .sslContext(sslContext) .followRedirects(HttpClient.Redirect.NORMAL) .build(); ``` After sending a request to the URL: ```java HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://example.com/initial-endpoint")) .GET() .build(); HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); ``` I receive the redirect behavior. I've tried manually handling the redirects by checking the response status code and then following the `Location` header, but it becomes cumbersome and feels like I'm reinventing the wheel. Is there a specific configuration or something I might be missing to ensure that redirects are handled correctly with a custom SSLContext? Any insights or solutions would be appreciated! This is part of a larger CLI tool I'm building. Is there a better approach? This is my first time working with Java stable. Any ideas how to fix this? Any pointers in the right direction?