本文整理汇总了Java中io.netty.handler.codec.http2.Http2Headers.add方法的典型用法代码示例。如果您正苦于以下问题:Java Http2Headers.add方法的具体用法?Java Http2Headers.add怎么用?Java Http2Headers.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.http2.Http2Headers
的用法示例。
在下文中一共展示了Http2Headers.add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toNettyHttp2
import io.netty.handler.codec.http2.Http2Headers; //导入方法依赖的package包/类
/**
* Converts the specified Armeria HTTP/2 headers into Netty HTTP/2 headers.
*/
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;
}
示例2: respondWithHttpError
import io.netty.handler.codec.http2.Http2Headers; //导入方法依赖的package包/类
private void respondWithHttpError(
ChannelHandlerContext ctx, int streamId, int code, Status.Code statusCode, String msg) {
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());
}
示例3: basicCorrectness
import io.netty.handler.codec.http2.Http2Headers; //导入方法依赖的package包/类
@Test
public void basicCorrectness() {
Http2Headers headers = new GrpcHttp2RequestHeaders(1);
headers.add(of(":method"), of("POST"));
headers.add(of("content-type"), of("application/grpc+proto"));
headers.add(of(":path"), of("/google.pubsub.v2.PublisherService/CreateTopic"));
headers.add(of(":scheme"), of("https"));
headers.add(of("te"), of("trailers"));
headers.add(of(":authority"), of("pubsub.googleapis.com"));
headers.add(of("foo"), of("bar"));
assertEquals(7, headers.size());
// Number of headers without the pseudo headers and 'te' header.
assertEquals(2, ((GrpcHttp2InboundHeaders)headers).numHeaders());
assertEquals(of("application/grpc+proto"), headers.get(of("content-type")));
assertEquals(of("/google.pubsub.v2.PublisherService/CreateTopic"), headers.path());
assertEquals(of("https"), headers.scheme());
assertEquals(of("POST"), headers.method());
assertEquals(of("pubsub.googleapis.com"), headers.authority());
assertEquals(of("trailers"), headers.get(of("te")));
assertEquals(of("bar"), headers.get(of("foo")));
}
示例4: binaryHeadersShouldBeBase64Decoded
import io.netty.handler.codec.http2.Http2Headers; //导入方法依赖的package包/类
@Test
public void binaryHeadersShouldBeBase64Decoded() {
Http2Headers headers = new GrpcHttp2RequestHeaders(1);
byte[] data = new byte[100];
new Random().nextBytes(data);
headers.add(of("foo-bin"), of(BaseEncoding.base64().encode(data)));
assertEquals(1, headers.size());
byte[][] namesAndValues = ((GrpcHttp2InboundHeaders)headers).namesAndValues();
assertEquals(of("foo-bin"), new AsciiString(namesAndValues[0]));
assertNotSame(data, namesAndValues[1]);
assertArrayEquals(data, namesAndValues[1]);
}
示例5: createResponseHeadersFromRequestHeaders
import io.netty.handler.codec.http2.Http2Headers; //导入方法依赖的package包/类
private static Http2Headers createResponseHeadersFromRequestHeaders(
Http2Headers requestHeaders) {
// Create response headers by echoing request headers.
Http2Headers responseHeaders = new DefaultHttp2Headers().status(OK.codeAsText());
for (Map.Entry<CharSequence, CharSequence> header : requestHeaders) {
if (!header.getKey().toString().startsWith(":")) {
responseHeaders.add("echo-" + header.getKey(), header.getValue());
}
}
responseHeaders.add("echo-method", requestHeaders.get(":method").toString());
return responseHeaders;
}
示例6: inboundCookiesMustBeMergedForHttp2
import io.netty.handler.codec.http2.Http2Headers; //导入方法依赖的package包/类
@Test
public void inboundCookiesMustBeMergedForHttp2() {
final Http2Headers in = new DefaultHttp2Headers();
in.add(HttpHeaderNames.COOKIE, "a=b; c=d");
in.add(HttpHeaderNames.COOKIE, "e=f;g=h");
in.addObject(HttpHeaderNames.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8);
in.add(HttpHeaderNames.COOKIE, "i=j");
in.add(HttpHeaderNames.COOKIE, "k=l;");
final HttpHeaders out = toArmeria(in);
assertThat(out.getAll(HttpHeaderNames.COOKIE))
.containsExactly("a=b; c=d; e=f; g=h; i=j; k=l");
}
示例7: http2Headers
import io.netty.handler.codec.http2.Http2Headers; //导入方法依赖的package包/类
default Http2Headers http2Headers() {
Http2Headers result = new DefaultHttp2Headers();
for (Entry<CharSequence, CharSequence> entry : this) {
result.add(entry.getKey(), entry.getValue());
}
return result;
}
示例8: testAddHeaders
import io.netty.handler.codec.http2.Http2Headers; //导入方法依赖的package包/类
@Test
public void testAddHeaders() {
Http2Headers other = new DefaultHttp2Headers();
other.add("header", "value");
headers.add(other);
assertEquals(other, headers.delegate());
assertEquals("value", headers.delegate().get("header"));
}