Search in sources :

Example 61 with DataFrame

use of org.eclipse.jetty.http2.frames.DataFrame in project jetty.project by eclipse.

the class HttpTransportOverHTTP2 method send.

private void send(ByteBuffer content, boolean lastContent, Callback callback) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("HTTP2 Response #{}/{}: {} content bytes{}", stream.getId(), Integer.toHexString(stream.getSession().hashCode()), content.remaining(), lastContent ? " (last chunk)" : "");
    }
    DataFrame frame = new DataFrame(stream.getId(), content, lastContent);
    stream.data(frame, callback);
}
Also used : DataFrame(org.eclipse.jetty.http2.frames.DataFrame)

Example 62 with DataFrame

use of org.eclipse.jetty.http2.frames.DataFrame in project jetty.project by eclipse.

the class HttpSenderOverHTTP2 method sendHeaders.

@Override
protected void sendHeaders(HttpExchange exchange, final HttpContent content, final Callback callback) {
    Request request = exchange.getRequest();
    String path = relativize(request.getPath());
    HttpURI uri = new HttpURI(request.getScheme(), request.getHost(), request.getPort(), path, null, request.getQuery(), null);
    MetaData.Request metaData = new MetaData.Request(request.getMethod(), uri, HttpVersion.HTTP_2, request.getHeaders());
    HeadersFrame headersFrame = new HeadersFrame(metaData, null, !content.hasContent());
    HttpChannelOverHTTP2 channel = getHttpChannel();
    Promise<Stream> promise = new Promise<Stream>() {

        @Override
        public void succeeded(Stream stream) {
            getHttpChannel().setStream(stream);
            stream.setIdleTimeout(request.getIdleTimeout());
            if (content.hasContent() && !expects100Continue(request)) {
                boolean advanced = content.advance();
                boolean lastContent = content.isLast();
                if (advanced || lastContent) {
                    DataFrame dataFrame = new DataFrame(stream.getId(), content.getByteBuffer(), lastContent);
                    stream.data(dataFrame, callback);
                    return;
                }
            }
            callback.succeeded();
        }

        @Override
        public void failed(Throwable failure) {
            callback.failed(failure);
        }
    };
    // TODO optimize the send of HEADERS and DATA frames.
    channel.getSession().newStream(headersFrame, promise, channel.getStreamListener());
}
Also used : Request(org.eclipse.jetty.client.api.Request) DataFrame(org.eclipse.jetty.http2.frames.DataFrame) HttpURI(org.eclipse.jetty.http.HttpURI) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) Promise(org.eclipse.jetty.util.Promise) MetaData(org.eclipse.jetty.http.MetaData) Stream(org.eclipse.jetty.http2.api.Stream)

Example 63 with DataFrame

use of org.eclipse.jetty.http2.frames.DataFrame in project jetty.project by eclipse.

the class HttpSenderOverHTTP2 method sendContent.

@Override
protected void sendContent(HttpExchange exchange, HttpContent content, Callback callback) {
    if (content.isConsumed()) {
        callback.succeeded();
    } else {
        Stream stream = getHttpChannel().getStream();
        DataFrame frame = new DataFrame(stream.getId(), content.getByteBuffer(), content.isLast());
        stream.data(frame, callback);
    }
}
Also used : Stream(org.eclipse.jetty.http2.api.Stream) DataFrame(org.eclipse.jetty.http2.frames.DataFrame)

Aggregations

DataFrame (org.eclipse.jetty.http2.frames.DataFrame)59 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)56 HttpFields (org.eclipse.jetty.http.HttpFields)55 MetaData (org.eclipse.jetty.http.MetaData)55 Stream (org.eclipse.jetty.http2.api.Stream)55 CountDownLatch (java.util.concurrent.CountDownLatch)54 Test (org.junit.Test)53 Session (org.eclipse.jetty.http2.api.Session)51 Callback (org.eclipse.jetty.util.Callback)47 FuturePromise (org.eclipse.jetty.util.FuturePromise)42 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)39 Promise (org.eclipse.jetty.util.Promise)30 HttpServletResponse (javax.servlet.http.HttpServletResponse)29 IOException (java.io.IOException)25 ServletException (javax.servlet.ServletException)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 ByteBuffer (java.nio.ByteBuffer)23 HttpServlet (javax.servlet.http.HttpServlet)23 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)20 ISession (org.eclipse.jetty.http2.ISession)18