HTTP/1.1 header parser error from HttpClient when proxy auth fails on Windows

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 11
      java 25.0.1 2025-10-21 LTS
      Java(TM) SE Runtime Environment (build 25.0.1+8-LTS-27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0.1+8-LTS-27, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      When using java.net.http.HttpClient on Windows, sending an HTTP POST through a proxy that requires authentication results in the error:

      HTTP/1.1 header parser received no bytes

      This occurs if no credentials or incorrect credentials are supplied. The same error can occur intermittently even when credential are supplied.

      On Linux, the same scenario correctly reports a credential-related error (e.g., No credentials provided).


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. In WSL, install tinyproxy (https://tinyproxy.github.io/) and configure it to require basic authentication:
      tinyproxy.conf:
      Port 8866
      Listen 127.0.0.1
      Timeout 600
      Allow 127.0.0.1
      BasicAuth abc xyz
      LogLevel Info
      2. On WSL, Start the proxy:
      $ tinyproxy -d -c ./tinyproxy.conf
      NOTICE [6068]: Initializing tinyproxy ...
      NOTICE [6068]: Reloading config file
      INFO [6068]: Added address [127.0.0.1] to listen addresses.
      INFO [6068]: Added basic auth user : abc
      NOTICE [6068]: Reloading config file finished
      INFO [6068]: listen_sock called with addr = '127.0.0.1'
      INFO [6068]: trying to listen on host[127.0.0.1], family[2], socktype[1], proto[6]
      INFO [6068]: listening on fd [3]
      INFO [6068]: Not running as root, so not changing UID/GID.
      INFO [6068]: Setting the various signals.
      INFO [6068]: Starting main loop. Accepting connections.
      3. On Windows, run the Java program (ProxyPost.java) that sends a POST request via this proxy but provides wrong credentials:
      > java ProxyPost.java
      Exception in thread "main" java.io.IOException: HTTP/1.1 header parser received no bytes
      ...

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An authentication error indicating invalid or missing credentials (as seen on Linux):

      $ java ProxyPost.java
      Exception in thread "main" java.io.IOException: No credentials provided
              at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:938)
              at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:133)
              at ProxyPost.main(ProxyPost.java:41)
      Caused by: java.io.IOException: No credentials provided
              at java.net.http/jdk.internal.net.http.AuthenticationFilter.response(AuthenticationFilter.java:319)
      ...
      ACTUAL -
      The program throws:

      Exception in thread "main" java.io.IOException: HTTP/1.1 header parser received no bytes
      at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:938)
      at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:133)
      at ProxyPost.main(ProxyPost.java:41)
      Caused by: java.io.IOException: HTTP/1.1 header parser received no bytes
      at java.net.http/jdk.internal.net.http.common.Utils.wrapWithExtraDetail(Utils.java:456)
      at java.net.http/jdk.internal.net.http.Http1Response$HeadersReader.onReadError(Http1Response.java:591)
      at java.net.http/jdk.internal.net.http.Http1AsyncReceiver.checkForErrors(Http1AsyncReceiver.java:304)
      at java.net.http/jdk.internal.net.http.Http1AsyncReceiver.flush(Http1AsyncReceiver.java:270)
      at java.net.http/jdk.internal.net.http.common.SequentialScheduler$LockingRestartableTask.run(SequentialScheduler.java:182)
      ...

      ---------- BEGIN SOURCE ----------
      import java.net.InetSocketAddress;
      import java.net.PasswordAuthentication;
      import java.net.ProxySelector;
      import java.net.URI;
      import java.net.Authenticator;
      import java.net.http.HttpClient;
      import java.net.http.HttpRequest;
      import java.net.http.HttpResponse;

      public class ProxyPost {
        public static void main(String[] args) throws Exception {

          HttpClient client = HttpClient.newBuilder()
            .proxy(ProxySelector.of(new InetSocketAddress("localhost", 8866)))
            .authenticator(new Authenticator() {
                @Override
                  protected PasswordAuthentication getPasswordAuthentication() {
                  if (getRequestorType() == RequestorType.PROXY) {
                    return new PasswordAuthentication(
                                                      "wrong",
                                                      "cred".toCharArray()
                                                      );
                  }
                  return null;
                }
              })
            .build();

          HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("http://httpbin.org/post"))
            .header("Content-Type", "text/plain; charset=UTF-8")
            .POST(
                  HttpRequest.BodyPublishers.ofString("some body text")
                  )
            .build();

          // Thread.sleep(2000);

          HttpResponse<String> response =
            client.send(request, HttpResponse.BodyHandlers.ofString());

          System.out.println("Status: " + response.statusCode());
          System.out.println("Response:");
          System.out.println(response.body());
        }
      }

      ---------- END SOURCE ----------

            Assignee:
            Daniel Jelinski
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: