Version: 9.4.30.v20200611 |

Pluggable Transports
Previous | Chapter 22. HTTP Client Home | Next

##### Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development

## Pluggable Transports

Jetty’s HTTP client can be configured to use different transports to carry the semantic of HTTP requests and responses.

This means that the intention of a client to request resource `/index.html` using the `GET` method can be carried over the network in different formats.

A HTTP client transport is the component that is in charge of converting a high-level, semantic, HTTP requests such as "GET resource /index.html" into the specific format understood by the server (for example, HTTP/2), and to convert the server response from the specific format (HTTP/2) into high-level, semantic objects that can be used by applications.

In this way, applications are not aware of the actual protocol being used. This allows them to write their logic against a high-level API that hides the details of the specific protocol being used over the network.

The most common protocol format is HTTP/1.1, a text-based protocol with lines separated by `\r\n`:

    GET /index.html HTTP/1.1\r\n
    Host: domain.com\r\n
    ...
    \r\n

However, the same request can be made using FastCGI, a binary protocol:

    x01 x01 x00 x01 x00 x08 x00 x00
    x00 x01 x01 x00 x00 x00 x00 x00
    x01 x04 x00 x01 xLL xLL x00 x00
    x0C x0B  D   O   C   U   M   E
     N   T   _   U   R   I   /   i
     n   d   e   x   .   h   t   m
     l
    ...

Similarly, HTTP/2 is a binary protocol that transports the same information in a yet different format.

### HTTP/1.1 Transport

HTTP/1.1 is the default transport.

    // No transport specified, using default.
    HttpClient client = new HttpClient();
    client.start();

If you want to customize the HTTP/1.1 transport, you can explicitly configure `HttpClient` in this way:

    int selectors = 1;
    HttpClientTransportOverHTTP transport = new HttpClientTransportOverHTTP(selectors);

    HttpClient client = new HttpClient(transport, null);
    client.start();

The example above allows you to customize the number of NIO selectors that `HttpClient` will be using.

### HTTP/2 Transport

The HTTP/2 transport can be configured in this way:

    HTTP2Client h2Client = new HTTP2Client();
    h2Client.setSelectors(1);
    HttpClientTransportOverHTTP2 transport = new HttpClientTransportOverHTTP2(h2Client);

    HttpClient client = new HttpClient(transport, null);
    client.start();

`HTTP2Client` is the lower-level client that provides an API based on HTTP/2 concepts such as sessions, streams and frames that are specific to HTTP/2.

`HttpClientTransportOverHTTP2` uses `HTTP2Client` to format high-level semantic HTTP requests ("GET resource /index.html") into the HTTP/2 specific format.

### FastCGI Transport

The FastCGI transport can be configured in this way:

    int selectors = 1;
    String scriptRoot = "/var/www/wordpress";
    HttpClientTransportOverFCGI transport = new HttpClientTransportOverFCGI(selectors, false, scriptRoot);

    HttpClient client = new HttpClient(transport, null);
    client.start();

In order to make requests using the FastCGI transport, you need to have a FastCGI server such as PHP-FPM (see also http://php.net/manual/en/install.fpm.php).

The FastCGI transport is primarily used by Jetty’s FastCGI support to serve PHP pages (WordPress for example).

Previous | Top | Next
Proxy Support | Home | Chapter 23. Maven and Jetty

See an error or something missing? Contribute to this documentation at Github!(Generated: 2020-06-11)