0

I have a server which replies first with status code 103 ( and some headers) and then with 200 ( plus some other headers) curl -I output below:

HTTP/2 103  
link: <https://cdn.shopify.com>; rel=preconnect, <https://cdn.shopify.com>; crossorigin; rel=preconnect
    
HTTP/2 200  
date: Mon, 08 Aug 2022 10:28:30 GMT content-type: text/html; charset=utf-8 x-sorting-hat-podid: 236 x-sorting-hat-shopid: 366627 x-storefront-renderer-rendered: 1 set-cookie: secure_customer_sig=;

My java.net.http.HttpClient seems to detect only the first status code (103) and reads only the first headers.

 HttpClient httpClient = HttpClient.newBuilder()
                .version(HttpClient.Version.HTTP_2)
                .followRedirects(HttpClient.Redirect.NORMAL)
                .connectTimeout(Duration.ofMinutes(1))
                .build();
 
 HttpRequest request = HttpRequest
    .newBuilder(httpReq, (name, value) -> true)
    .header("user-agent", "Mozilla/5.0 (X11....")
    //other headers here
    .build();

 HttpResponse<InputStream> response = httpClient.send(
                    request,
                    HttpResponse.BodyHandlers.ofInputStream()
            );

 logger.debug("call returned status code {}", response.statusCode());

The code above only shows 103 as status code ( which is an intermediary status code as you saw in the output of curl). How do I skip that status code + its headers ? I'm only interested in the final (200) status code and the subsequent headers.

humbletrader
  • 396
  • 2
  • 10

1 Answers1

0

Unfortunately I have only a workaround which I will post here in order to help others : I changed the HTTP 2 to HTTP 1.1. Feel free to find a better option . On my side I'm thinking about changing java's HttpClient with a more robust HttpClient implementation

humbletrader
  • 396
  • 2
  • 10