Configuring a Jetty WebSocket Client to Use a Proxy Server

I did not find a solution about this. Jetty doesn't seem to support this feature yet. Maybe I'm wrong, please enlighten me.

I have a very simple Java client that connects to a Java server in localhost:8080 . I would like to add a transparent proxy between them to simulate what we could find on the company's private network.

+5
source share
2 answers

Update: May 2017

Starting with Jetty 9.4.0 onwards, the proprietary Jetty WebSocketClient supports Proxies through the Jetty HttpClient.

This works by declaring the HttpClient along with its proxy configurations, and then passing this the WebSocketClient constructor for use.

This only works with the following:

  • Upgrading HTTP / 1.1 to WebSocket
  • Native Jetty WebSocket API

This does not work with the following:

  • HTTP / 2 (there is no specification for WebSocket over HTTP / 2 yet)
  • JSR356 javax.websocket (there are ideas for the API that violate changes in the JSR356 ClientContainer to allow the Jetty HttpClient to be passed through the constructor, let us know if this is a viable option for you to submit a new problem to github , saying so)

Original answer

With Jetty 9, there is no proxy support for the Jetty Native WebSocket client or for implementing the JSR-356 client (javax.websocket).

This support is planned for Jetty 10 (which tracks Servlet 4) and will result in a complete redesign of the entire set of client libraries in Jetty to have equal support for:

  • HTTP / 1.1
  • HTTP / 2 (native / direct)
  • Update HTTP / 1.1 to HTTP / 2 (h2c)
  • Upgrading HTTP / 1.1 to WebSocket
  • HTTP / 2 websocket channel (currently in draft)
  • Proxy support.
  • Cookie support
  • etc.

Existing Jetty WebSocket client implementations are self-contained due to JSR-356 support requirements.

The existing WebSocket client does not use the existing Jetty HttpClient in Jetty 9.x. If so, then proxy support may perhaps work with a very limited set of scenarios.

This is a low priority feature request, as there are several existing proxies that still support WebSocket (in fact, they generally do not support HTTP / 1.1 updates very well). Even the proprietary Jetty Proxy server does not currently support HTTP / 1.1 updates.

+6
source

As shown in Figure 2 in How HTML5 web sockets interact with proxies , if you are trying to use a transparent proxy, you do not need to require client-side proxy support. On the other hand, the proxy server explicitly requires client libraries to support the proxy server.

The Jetty WebSocket client will not have problems if your proxy is transparent.

+2
source

Source: https://habr.com/ru/post/1232285/


All Articles