List of usage examples for io.netty.handler.codec.http2 DefaultHttp2Headers DefaultHttp2Headers
@SuppressWarnings("unchecked") public DefaultHttp2Headers(boolean validate, int arraySizeHint)
From source file:com.linecorp.armeria.internal.ArmeriaHttpUtil.java
License:Apache License
/** * Converts the specified Armeria HTTP/2 headers into Netty HTTP/2 headers. */// ww w .j av a 2 s .com public static Http2Headers toNettyHttp2(HttpHeaders in) { final Http2Headers out = new DefaultHttp2Headers(false, in.size()); out.set(in); out.remove(HttpHeaderNames.CONNECTION); out.remove(HttpHeaderNames.TRANSFER_ENCODING); out.remove(HttpHeaderNames.TRAILER); if (!out.contains(HttpHeaderNames.COOKIE)) { return out; } // Split up cookies to allow for better compression. // https://tools.ietf.org/html/rfc7540#section-8.1.2.5 final List<CharSequence> cookies = out.getAllAndRemove(HttpHeaderNames.COOKIE); for (CharSequence c : cookies) { out.add(HttpHeaderNames.COOKIE, COOKIE_SPLITTER.split(c)); } return out; }
From source file:com.linecorp.armeria.internal.http.ArmeriaHttpUtil.java
License:Apache License
public static Http2Headers toNettyHttp2(HttpHeaders inputHeaders) { final Http2Headers outputHeaders = new DefaultHttp2Headers(false, inputHeaders.size()); outputHeaders.set(inputHeaders);// w w w .java2 s . c om outputHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING); outputHeaders.remove(HttpHeaderNames.TRAILER); return outputHeaders; }
From source file:io.grpc.netty.InboundHeadersBenchmark.java
License:Apache License
/** * Checkstyle./*from w w w . j ava 2s .c o m*/ */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void defaultHeaders_serverHandler(Blackhole bh) { serverHandler(bh, new DefaultHttp2Headers(true, 9)); }
From source file:io.grpc.netty.InboundHeadersBenchmark.java
License:Apache License
/** * Checkstyle.//from w w w . j a v a 2 s. c om */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void defaultHeaders_clientHandler(Blackhole bh) { clientHandler(bh, new DefaultHttp2Headers(true, 2)); }
From source file:io.grpc.netty.NettyServerHandler.java
License:Apache License
private void respondWithHttpError(ChannelHandlerContext ctx, int streamId, int code, Status.Code statusCode, String msg) {/*from w w w . ja va 2 s . c o m*/ Metadata metadata = new Metadata(); metadata.put(InternalStatus.CODE_KEY, statusCode.toStatus()); metadata.put(InternalStatus.MESSAGE_KEY, msg); byte[][] serialized = InternalMetadata.serialize(metadata); Http2Headers headers = new DefaultHttp2Headers(true, serialized.length / 2).status("" + code) .set(CONTENT_TYPE_HEADER, "text/plain; encoding=utf-8"); for (int i = 0; i < serialized.length; i += 2) { headers.add(new AsciiString(serialized[i], false), new AsciiString(serialized[i + 1], false)); } encoder().writeHeaders(ctx, streamId, headers, 0, false, ctx.newPromise()); ByteBuf msgBuf = ByteBufUtil.writeUtf8(ctx.alloc(), msg); encoder().writeData(ctx, streamId, msgBuf, 0, true, ctx.newPromise()); }