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();
httpClient.start();

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();
spdyClientFactory.start();
// 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);
httpSPDYClient.start();
// Send request, receive response
ContentResponse response = httpSPDYClient.newRequest("http://host/path")
        .method("GET")
        .send();

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.


2 Comments

Hans · 17/11/2013 at 11:48

How/where is the FastCGI support implemented? I can’t find it anywhere in the code (I searched the jetty-9.1 branch of the git repo). Thank.

    gregw · 09/12/2013 at 20:52

    Currently it is not in the open source repository. We are considering how we want to release it and will make a decision soon. Please contact sbordet@intalio.com for more options.

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *