Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8286052

Proxy-authorization header not sent anymore with WebView

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx17
    • javafx
    • None
    • web
    • generic
    • generic

      Since the introduction of HTTP2 in JDK-8211308, it seems that the proxy-authorization header is not sent anymore with the WebView.

      Step to reproduce:
      1) Start a proxy (I use Fiddler on my side)
      2) Activate basic proxy authentication for example (on Fiddler under "Rules" -> "Require proxy authentication")
      3) Run this sample :

      "
      import java.io.IOException;
      import java.net.Authenticator;
      import java.net.InetSocketAddress;
      import java.net.PasswordAuthentication;
      import java.net.Proxy;
      import java.net.ProxySelector;
      import java.net.SocketAddress;
      import java.net.URI;
      import java.util.ArrayList;
      import java.util.List;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.VBox;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;

      public class ProxyAuthenticationWebView extends Application {
          static {
              // Allow basic authentication to work
              System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
              System.setProperty("jdk.http.auth.proxying.disabledSchemes", "");
              // ACTIVATE THIS LINE TO MAKE IT WORK
              //System.setProperty("com.sun.webkit.useHTTP2Loader", "false");
          }

          public static void main(String[] args) {
              launch(args);
          }

          @Override
          public void start(Stage stage) {
              // Set the default user and password here
              Authenticator.setDefault(new Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication("1", "1".toCharArray());
                  }
              });

              // Use the Fiddler proxy
              Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8888));
              List<Proxy> proxyList = new ArrayList<>();
              proxyList.add(proxy);
              
              ProxySelector.setDefault(new ProxySelector() {
                  @Override
                  public List<Proxy> select(URI uri) {
                      return proxyList;
                  }

                  @Override
                  public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
                      throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
                  }
              });

              stage.setWidth(1280);
              stage.setHeight(720);

              WebView webView = new WebView();

              webView.getEngine().load("http://google.com");
              VBox vbox = new VBox(webView);

              Scene scene = new Scene(vbox);

              stage.setScene(scene);
              stage.show();
          }
      }
      "

      Actual Results:
      When you launch the program, you will see that no header "Proxy-authorization" is sent. Therefore, the page cannot be reached.

      Expected results:
      It you un-comment the line "System.setProperty("com.sun.webkit.useHTTP2Loader", "false");"
      You will see that the Proxy-authorization header is well sent.

            jbhaskar Jay Bhaskar
            shadzic Samir Hadzic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: