java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.http3.client.HTTP3Client
All Implemented Interfaces:
org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle

public class HTTP3Client extends org.eclipse.jetty.util.component.ContainerLifeCycle

HTTP3Client provides an asynchronous, non-blocking implementation to send HTTP/3 frames to a server.

Typical usage:

 // HTTP3Client setup.

 HTTP3Client client = new HTTP3Client();

 // To configure QUIC properties.
 QuicConfiguration quicConfig = client.getQuicConfiguration();

 // To configure HTTP/3 properties.
 HTTP3Configuration h3Config = client.getHTTP3Configuration();

 client.start();

 // HTTP3Client request/response usage.

 // Connect to host.
 String host = "webtide.com";
 int port = 443;
 Session.Client session = client
     .connect(new InetSocketAddress(host, port), new Session.Client.Listener() {})
     .get(5, TimeUnit.SECONDS);

 // Prepare the HTTP request headers.
 HttpFields requestFields = new HttpFields();
 requestFields.put("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION);

 // Prepare the HTTP request object.
 MetaData.Request request = new MetaData.Request("PUT", HttpURI.from("https://" + host + ":" + port + "/"), HttpVersion.HTTP_3, requestFields);

 // Create the HTTP/3 HEADERS frame representing the HTTP request.
 HeadersFrame headersFrame = new HeadersFrame(request, false);

 // Send the HEADERS frame to create a request stream.
 Stream stream = session.newRequest(headersFrame, new Stream.Listener()
 {
     @Override
     public void onResponse(Stream stream, HeadersFrame frame)
     {
         // Inspect the response status and headers.
         MetaData.Response response = (MetaData.Response)frame.getMetaData();

         // Demand for response content.
         stream.demand();
     }

     @Override
     public void onDataAvailable(Stream stream)
     {
         Stream.Data data = stream.readData();
         if (data != null)
         {
             // Process the response content chunk.
         }
         // Demand for more response content.
         stream.demand();
     }
 }).get(5, TimeUnit.SECONDS);

 // Use the Stream object to send request content, if any, using a DATA frame.
 ByteBuffer requestChunk1 = ...;
 stream.data(new DataFrame(requestChunk1, false))
     // Subsequent sends must wait for previous sends to complete.
     .thenCompose(s ->
     {
         ByteBuffer requestChunk2 = ...;
         s.data(new DataFrame(requestChunk2, true)));
     }
 

IMPLEMENTATION NOTES.

Each call to connect(SocketAddress, Session.Client.Listener) creates a new DatagramChannelEndPoint with the correspondent ClientQuicConnection.

Each ClientQuicConnection manages one ClientQuicSession with the corresponding ClientHTTP3Session.

Each ClientHTTP3Session manages the mandatory encoder, decoder and control streams, plus zero or more request/response streams.

 GENERIC, TCP-LIKE, SETUP FOR HTTP/1.1 AND HTTP/2
 HTTP3Client - dgramEP - ClientQuiConnection - ClientQuicSession - ClientProtocolSession - TCPLikeStream

 SPECIFIC SETUP FOR HTTP/3
                                                                                      /- [Control|Decoder|Encoder]Stream
 HTTP3Client - dgramEP - ClientQuiConnection - ClientQuicSession - ClientHTTP3Session -* HTTP3Streams
 

HTTP/3+QUIC support is experimental and not suited for production use. APIs may change incompatibly between releases.

  • Nested Class Summary

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

    org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

    org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, STARTED, STARTING, STOPPED, STOPPING

    Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

    KEY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    CompletableFuture<org.eclipse.jetty.http3.api.Session.Client>
    connect(SocketAddress address, org.eclipse.jetty.http3.api.Session.Client.Listener listener)
     
    CompletableFuture<org.eclipse.jetty.http3.api.Session.Client>
    connect(SocketAddress address, org.eclipse.jetty.http3.api.Session.Client.Listener listener, Map<String,Object> context)
     
    protected void
     
    org.eclipse.jetty.io.ClientConnector
     
    org.eclipse.jetty.http3.HTTP3Configuration
     
    org.eclipse.jetty.quic.common.QuicConfiguration
     
     

    Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

    addBean, addBean, addEventListener, addManaged, contains, destroy, doStop, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.jetty.util.component.Container

    getCachedBeans, getEventListeners

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

    dumpSelf

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    isDumpable
  • Field Details

    • CLIENT_CONTEXT_KEY

      public static final String CLIENT_CONTEXT_KEY
    • SESSION_LISTENER_CONTEXT_KEY

      public static final String SESSION_LISTENER_CONTEXT_KEY
    • SESSION_PROMISE_CONTEXT_KEY

      public static final String SESSION_PROMISE_CONTEXT_KEY
  • Constructor Details

    • HTTP3Client

      public HTTP3Client()
  • Method Details

    • getClientConnector

      public org.eclipse.jetty.io.ClientConnector getClientConnector()
    • getQuicConfiguration

      public org.eclipse.jetty.quic.common.QuicConfiguration getQuicConfiguration()
    • getHTTP3Configuration

      public org.eclipse.jetty.http3.HTTP3Configuration getHTTP3Configuration()
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • connect

      public CompletableFuture<org.eclipse.jetty.http3.api.Session.Client> connect(SocketAddress address, org.eclipse.jetty.http3.api.Session.Client.Listener listener)
    • connect

      public CompletableFuture<org.eclipse.jetty.http3.api.Session.Client> connect(SocketAddress address, org.eclipse.jetty.http3.api.Session.Client.Listener listener, Map<String,Object> context)
    • shutdown

      public CompletableFuture<Void> shutdown()