HttpConversionUtil { public static Http2Headers toHttp2Headers(HttpMessage in, boolean validateHeaders) { HttpHeaders inHeaders = in.headers(); final Http2Headers out = new DefaultHttp2Headers(validateHeaders, inHeaders.size()); if (in instanceof HttpRequest) { HttpRequest request = (HttpRequest) in; URI requestTargetUri = URI.create(request.uri()); out.path(toHttp2Path(requestTargetUri)); out.method(request.method().asciiName()); setHttp2Scheme(inHeaders, requestTargetUri, out); if (!isOriginForm(requestTargetUri) && !isAsteriskForm(requestTargetUri)) { String host = inHeaders.getAsString(HttpHeaderNames.HOST); setHttp2Authority((host == null || host.isEmpty()) ? requestTargetUri.getAuthority() : host, out); } } else if (in instanceof HttpResponse) { HttpResponse response = (HttpResponse) in; out.status(response.status().codeAsText()); } toHttp2Headers(inHeaders, out); return out; } private  HttpConversionUtil(); static HttpResponseStatus parseStatus(CharSequence status); static FullHttpResponse toFullHttpResponse(int streamId, Http2Headers http2Headers, ByteBufAllocator alloc,
                                                      boolean validateHttpHeaders); static FullHttpRequest toFullHttpRequest(int streamId, Http2Headers http2Headers, ByteBufAllocator alloc,
                                                boolean validateHttpHeaders); static HttpRequest toHttpRequest(int streamId, Http2Headers http2Headers, boolean validateHttpHeaders); static HttpResponse toHttpResponse(final int streamId,
                                              final Http2Headers http2Headers,
                                              final boolean validateHttpHeaders); static void addHttp2ToHttpHeaders(int streamId, Http2Headers sourceHeaders,
                    FullHttpMessage destinationMessage, boolean addToTrailer); static void addHttp2ToHttpHeaders(int streamId, Http2Headers inputHeaders, HttpHeaders outputHeaders,
            HttpVersion httpVersion, boolean isTrailer, boolean isRequest); static Http2Headers toHttp2Headers(HttpMessage in, boolean validateHeaders); static Http2Headers toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders); static void toHttp2Headers(HttpHeaders inHeaders, Http2Headers out); static final HttpMethod OUT_OF_MESSAGE_SEQUENCE_METHOD; static final String OUT_OF_MESSAGE_SEQUENCE_PATH; static final HttpResponseStatus OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE; }
@Test public void stripTEHeaders() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.add(TE, GZIP); Http2Headers out = new DefaultHttp2Headers(); HttpConversionUtil.toHttp2Headers(inHeaders, out); assertTrue(out.isEmpty()); }
@Test public void stripTEHeadersExcludingTrailers() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.add(TE, GZIP); inHeaders.add(TE, TRAILERS); Http2Headers out = new DefaultHttp2Headers(); HttpConversionUtil.toHttp2Headers(inHeaders, out); assertSame(TRAILERS, out.get(TE)); }
@Test public void stripTEHeadersCsvSeparatedExcludingTrailers() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.add(TE, GZIP + "," + TRAILERS); Http2Headers out = new DefaultHttp2Headers(); HttpConversionUtil.toHttp2Headers(inHeaders, out); assertSame(TRAILERS, out.get(TE)); }
@Test public void stripTEHeadersCsvSeparatedAccountsForValueSimilarToTrailers() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.add(TE, GZIP + "," + TRAILERS + "foo"); Http2Headers out = new DefaultHttp2Headers(); HttpConversionUtil.toHttp2Headers(inHeaders, out); assertFalse(out.contains(TE)); }
@Test public void stripTEHeadersAccountsForValueSimilarToTrailers() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.add(TE, TRAILERS + "foo"); Http2Headers out = new DefaultHttp2Headers(); HttpConversionUtil.toHttp2Headers(inHeaders, out); assertFalse(out.contains(TE)); }
@Test public void stripTEHeadersAccountsForOWS() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.add(TE, " " + TRAILERS + " "); Http2Headers out = new DefaultHttp2Headers(); HttpConversionUtil.toHttp2Headers(inHeaders, out); assertSame(TRAILERS, out.get(TE)); }
@Test public void stripConnectionHeadersAndNominees() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.add(CONNECTION, "foo"); inHeaders.add("foo", "bar"); Http2Headers out = new DefaultHttp2Headers(); HttpConversionUtil.toHttp2Headers(inHeaders, out); assertTrue(out.isEmpty()); }
@Test public void stripConnectionNomineesWithCsv() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.add(CONNECTION, "foo, bar"); inHeaders.add("foo", "baz"); inHeaders.add("bar", "qux"); inHeaders.add("hello", "world"); Http2Headers out = new DefaultHttp2Headers(); HttpConversionUtil.toHttp2Headers(inHeaders, out); assertEquals(1, out.size()); assertSame("world", out.get("hello")); }