In Jetty 9, the
HttpClient was completely rewritten, as we posted a while back.
In Jetty 9.1, we took one step forward and we made Jetty’s
HttpClient polyglot. This means that now applications can use the HTTP API and semantic (“I want to GET the resource at the http://host/myresource URI”) but can now choose how this request is carried over the network.
Currently, three transports are implemented: HTTP, SPDY and FastCGI.
The usage is really simple; the following snippet shows how to setup
HttpClient with the default HTTP transport:
// Default transport uses HTTP
HttpClient httpClient = new HttpClient();
while the next snippet shows how to setup
HttpClient with the SPDY transport:
// Using the SPDY transport in clear text
// Create the SPDYClient factory
SPDYClient.Factory spdyClientFactory = new SPDYClient.Factory();
// Create the SPDYClient
SPDYClient spdyClient = spdyClientFactory.newSPDYClient(SPDY.V3);
// Create the HttpClient transport
HttpClientTransport transport = new HttpClientTransportOverSPDY(spdyClient);
// HTTP over SPDY !
HttpClient httpSPDYClient = new HttpClient(transport, null);
// Send request, receive response
ContentResponse response = httpSPDYClient.newRequest("http://host/path")
This last snippet allows the application to still use the HTTP API, but have the request and the response transported via SPDY, rather than HTTP.
Why this is useful ?
First of all, more and more websites are converting to SPDY because it offers performance improvements (and if you use Jetty as the server behind your website, the performance improvements can be stunning, check out this video).
This means that with a very simple change in the
HttpClient configuration, your client application connecting to servers can benefit of the performance boost that SPDY provides.
If you are using
HttpClient for server-to-server communication, you can use SPDY in clear text (rather than encrypted) to achieve even more efficiency because there is no encryption involved. Jetty is perfectly capable of speaking SPDY in clear text, so this could be a major performance win for your applications.
Furthermore, you can parallelize HTTP requests thanks to SPDY’s multiplexing rather than opening multiple connections, saving network resources.
I encourage you to try out these features and report your feedback here in the comments or on the Jetty mailing list.