Example usage for io.netty.handler.codec.http2 DefaultHttp2Headers.Builder add

List of usage examples for io.netty.handler.codec.http2 DefaultHttp2Headers.Builder add

Introduction

In this page you can find the example usage for io.netty.handler.codec.http2 DefaultHttp2Headers.Builder add.

Prototype

T add(K name, V value);

Source Link

Document

Adds a new header with the specified name and value .

Usage

From source file:Http2ClientConnectionHandler.java

License:Apache License

/**
 * Handles conversion of a {@link FullHttpMessage} to HTTP/2 frames.
 *///from   www .  j  a v a  2 s.  c  om
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
    if (msg instanceof FullHttpMessage) {
        FullHttpMessage httpMsg = (FullHttpMessage) msg;
        boolean hasData = httpMsg.content().isReadable();

        // Convert and write the headers.
        DefaultHttp2Headers.Builder headers = DefaultHttp2Headers.newBuilder();
        for (Map.Entry<String, String> entry : httpMsg.headers().entries()) {
            headers.add(entry.getKey(), entry.getValue());
        }
        int streamId = nextStreamId();
        writeHeaders(ctx, promise, streamId, headers.build(), 0, !hasData, false);
        if (hasData) {
            writeData(ctx, ctx.newPromise(), streamId, httpMsg.content(), 0, true, true);
        }
    } else {
        ctx.write(msg, promise);
    }
}

From source file:Http2ClientConnectionHandler.java

License:Apache License

public Promise<FullHttpResponse> send(final FullHttpRequest request) {
    boolean hasData = request.content().isReadable();

    // Convert and write the headers.
    DefaultHttp2Headers.Builder headers = DefaultHttp2Headers.newBuilder();
    for (Map.Entry<String, String> entry : request.headers().entries()) {
        headers.add(entry.getKey(), entry.getValue());
    }//  w  w w.j a va  2  s  .co m
    synchronized (this) {
        streamIdCounter += 2;
        final int streamId = streamIdCounter;
        //      System.err.println("send: " + streamId);
        final OutstandingRequest outstandingRequest = new OutstandingRequest();
        outstanding.put(streamId, outstandingRequest);
        writeHeaders(ctx, ctx.newPromise(), streamId, headers.build(), 0, !hasData, false);
        if (hasData) {
            writeData(ctx, ctx.newPromise(), streamId, request.content(), 0, true, true);
        }
        return outstandingRequest.promise;
    }
}