Jetty Logo
Version: 9.2.3.v20140905
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 from 1 day to full product delivery

Other Features

Cookies Support
Authentication Support
Proxy Support

Cookies Support

Jetty HTTP client supports cookies out of the box. The HttpClient instance receives cookies from HTTP responses and stores them in a java.net.CookieStore, a class that is part of the JDK. When new requests are made, the cookie store is consulted and if there are matching cookies (that is, cookies that are not expired and that match domain and path of the request) then they are added to the requests.

Applications can programmatically access the cookie store to find the cookies that have been set:

Applications can also programmatically set cookies as if they were returned from a HTTP response:

You can remove cookies that you do not want to be sent in future HTTP requests:

If you want to totally disable cookie handling, you can install a HttpCookieStore.Empty instance in this way:

You can enable cookie filtering by installing a cookie store that performs the filtering logic in this way:

The example above will retain only cookies that come from the google.com domain or sub-domains.

Authentication Support

Jetty HTTP client supports the "Basic" and "Digest" authentication mechanisms defined by RFC 2617.

You can configure authentication credentials in the HTTP client instance as follows:

Jetty HTTP client tests authentication credentials against the challenge(s) the server issues, and if they match it automatically sends the right authentication headers to the server for authentication. If the authentication is successful, it caches the result and reuses it for subsequent requests for the same domain and matching URIs.

Successful authentications are cached, but it is possible to clear them in order to force authentication again:

Proxy Support

Jetty's HTTP client can be configured to use proxies to connect to destinations.

Two types of proxies are available out of the box: a HTTP proxy (provided by class org.eclipse.jetty.client.HttpProxy) and a SOCKS 4 proxy (provided by class org.eclipse.jetty.client.Socks4Proxy). Other implementations may be written by subclassing ProxyConfiguration.Proxy.

A typical configuration is the following:

You specify the proxy host and port, and optionally also the addresses that you do not want to be proxied, and then set the proxy configuration on the HttpClient instance.

Configured in this way, HttpClient makes requests to the HTTP proxy (for plain-text HTTP requests) or establishes a tunnel via HTTP CONNECT (for encrypted HTTPS requests).

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-10-25T01:00:35-07:00)