Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Jetty WebSocket Client to use proxy

I haven't found any solution about this. It seems Jetty doesn't support this feature yet. I might be wrong so please, enlighten me.

I've got a very simple Java client which connects to a Java server at localhost:8080. I would like to add a transparent proxy between them in order to simulate what we could find in a company's private network.

like image 812
Grégoire Borel Avatar asked Sep 25 '15 14:09

Grégoire Borel


2 Answers

Update: May, 2017

Starting in Jetty 9.4.0 and onwards, the native Jetty WebSocketClient supports Proxies via the Jetty HttpClient.

This works by declaring an HttpClient, along with its proxy configurations, and then handing that off to the WebSocketClient constructor to use.

This only works with the following:

  • HTTP/1.1 upgrade to WebSocket
  • Native Jetty WebSocket APIs

This does not work with the following:

  • HTTP/2 (there is no spec for WebSocket over HTTP/2 as of yet)
  • JSR356 javax.websocket (there are ideas for API breaking changes to the JSR356 ClientContainer to allow passing in a Jetty HttpClient via a constructor, let us know if this is viable option for you by filing a new issue on github saying so)

Original Answer

With Jetty 9, there's no Proxy support for either the Jetty Native WebSocket client, or the JSR-356 (javax.websocket) client implementation.

This support is scheduled for Jetty 10 (which is tracking Servlet 4), and will result in a complete reworking of the entire client library suite in Jetty to have equal support for :

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

The existing WebSocket client implementations on Jetty are standalone, due to the JSR-356 support requirements.

The existing WebSocket client does not leverage the existing Jetty HttpClient in Jetty 9.x. If it did then proxy support could, maybe, under a very limited set of scenarios, work.

This is a low priority feature request, as there are few existing proxies out there that support WebSocket so far (actually, they have generally bad support for HTTP/1.1 upgrade). Even Jetty's own Server side Proxy does not currently support HTTP/1.1 upgraded connections.

like image 197
Joakim Erdfelt Avatar answered Nov 01 '22 11:11

Joakim Erdfelt


According to Figure 2 in How HTML5 Web Sockets Interact With Proxy Servers, if you are trying to use a transparent proxy, you don't have to require a proxy support on the client side. On the other hand, an explicit proxy requires client libraries to support proxy.

Jetty WebSocket client won't have any problem if your proxy is transparent.

like image 2
Takahiko Kawasaki Avatar answered Nov 01 '22 10:11

Takahiko Kawasaki