Java Code Examples for io.netty.handler.codec.http2.DefaultHttp2Headers#add()
The following examples show how to use
io.netty.handler.codec.http2.DefaultHttp2Headers#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UtilsTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@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); 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())); }
Example 2
Source File: UtilsTest.java From grpc-java with Apache License 2.0 | 6 votes |
@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); 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())); }
Example 3
Source File: HeadersBenchmark.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Setup(Level.Trial) public void setup() { Map<String, String> headers = ExampleHeaders.EXAMPLES.get(exampleHeader); httpNames = new AsciiString[headers.size()]; http2Names = new AsciiString[headers.size()]; httpValues = new AsciiString[headers.size()]; httpHeaders = new DefaultHttpHeaders(false); http2Headers = new DefaultHttp2Headers(false); int idx = 0; for (Map.Entry<String, String> header : headers.entrySet()) { String name = header.getKey(); String httpName = toHttpName(name); String http2Name = toHttp2Name(name); String value = header.getValue(); httpNames[idx] = new AsciiString(httpName); http2Names[idx] = new AsciiString(http2Name); httpValues[idx] = new AsciiString(value); httpHeaders.add(httpNames[idx], httpValues[idx]); http2Headers.add(http2Names[idx], httpValues[idx]); idx++; } slowHttp2Headers = new SlowHeaders(http2Headers); emptyHttpHeaders = new DefaultHttpHeaders(true); emptyHttp2Headers = new DefaultHttp2Headers(true); emptyHttpHeadersNoValidate = new DefaultHttpHeaders(false); emptyHttp2HeadersNoValidate = new DefaultHttp2Headers(false); }
Example 4
Source File: HeadersBenchmark.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Benchmark @BenchmarkMode(Mode.AverageTime) public DefaultHttp2Headers http2Put() { DefaultHttp2Headers headers = new DefaultHttp2Headers(false); for (int i = 0; i < http2Names.length; i++) { headers.add(http2Names[i], httpValues[i]); } return headers; }
Example 5
Source File: UtilsTest.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@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); 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()); }
Example 6
Source File: UtilsTest.java From grpc-java with Apache License 2.0 | 4 votes |
@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); 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()); }