List of usage examples for io.netty.handler.codec.http2 DefaultHttp2Headers get
V get(K name);
From source file:io.grpc.netty.UtilsTest.java
License:Apache License
@Test public void convertClientHeaders_sanitizes() { Metadata metaData = new Metadata(); // Intentionally being explicit here rather than relying on any pre-defined lists of headers, // since the goal of this test is to validate the correctness of such lists in the first place. metaData.put(GrpcUtil.CONTENT_TYPE_KEY, "to-be-removed"); metaData.put(GrpcUtil.USER_AGENT_KEY, "to-be-removed"); metaData.put(GrpcUtil.TE_HEADER, "to-be-removed"); metaData.put(userKey, userValue);/*from ww w.j av a2s.c om*/ String scheme = "https"; String userAgent = "user-agent"; String method = "POST"; String authority = "authority"; String path = "//testService/test"; Http2Headers output = Utils.convertClientHeaders(metaData, new AsciiString(scheme), new AsciiString(path), new AsciiString(authority), new AsciiString(method), new AsciiString(userAgent)); DefaultHttp2Headers headers = new DefaultHttp2Headers(); for (Map.Entry<CharSequence, CharSequence> entry : output) { headers.add(entry.getKey(), entry.getValue()); } // 7 reserved headers, 1 user header assertEquals(7 + 1, headers.size()); // Check the 3 reserved headers that are non pseudo // Users can not create pseudo headers keys so no need to check for them here assertEquals(GrpcUtil.CONTENT_TYPE_GRPC, headers.get(GrpcUtil.CONTENT_TYPE_KEY.name()).toString()); assertEquals(userAgent, headers.get(GrpcUtil.USER_AGENT_KEY.name()).toString()); assertEquals(GrpcUtil.TE_TRAILERS, headers.get(GrpcUtil.TE_HEADER.name()).toString()); // Check the user header is in tact assertEquals(userValue, headers.get(userKey.name()).toString()); }
From source file:io.grpc.netty.UtilsTest.java
License:Apache License
@Test @SuppressWarnings("UndefinedEquals") // AsciiString.equals public void convertServerHeaders_sanitizes() { Metadata metaData = new Metadata(); // Intentionally being explicit here rather than relying on any pre-defined lists of headers, // since the goal of this test is to validate the correctness of such lists in the first place. metaData.put(GrpcUtil.CONTENT_TYPE_KEY, "to-be-removed"); metaData.put(GrpcUtil.TE_HEADER, "to-be-removed"); metaData.put(GrpcUtil.USER_AGENT_KEY, "to-be-removed"); metaData.put(userKey, userValue);/*from w w w . ja va2 s. c o m*/ Http2Headers output = Utils.convertServerHeaders(metaData); DefaultHttp2Headers headers = new DefaultHttp2Headers(); for (Map.Entry<CharSequence, CharSequence> entry : output) { headers.add(entry.getKey(), entry.getValue()); } // 2 reserved headers, 1 user header assertEquals(2 + 1, headers.size()); assertEquals(Utils.CONTENT_TYPE_GRPC, headers.get(GrpcUtil.CONTENT_TYPE_KEY.name())); }