public static <R extends Request> Http2Headers toHttp2Headers(R request) throws Exception
  {
    URI uri = request.getURI();
    URL url = new URL(uri.toString());

    String method = request.getMethod();
    String authority = url.getAuthority();
    String path = url.getFile();
    String scheme = uri.getScheme();

    // RFC 2616, section 5.1.2:
    //   Note that the absolute path cannot be empty; if none is present in the original URI,
    //   it MUST be given as "/" (the server root).
    path = path.isEmpty() ? "/" : path;

    final Http2Headers headers = new DefaultHttp2Headers()
        .method(method)
        .authority(authority)
        .path(path)
        .scheme(scheme);
    for (Map.Entry<String, String> entry : request.getHeaders().entrySet())
    {
      // Ignores HTTP/2 blacklisted headers
      if (HEADER_BLACKLIST.contains(entry.getKey().toLowerCase()))
      {
        continue;
      }

      // RFC 7540, section 8.1.2:
      //   ... header field names MUST be converted to lowercase prior to their
      //   encoding in HTTP/2.  A request or response containing uppercase
      //   header field names MUST be treated as malformed (Section 8.1.2.6).
      String name = entry.getKey().toLowerCase();
      String value = entry.getValue();
      headers.set(name, value == null ? "" : value);
    }

    // Split up cookies to allow for better header compression
    headers.set(HttpHeaderNames.COOKIE, request.getCookies());

    return headers;
  }
@Test
  public void testStreamToHttp2HeadersRegularHeaders() throws Exception
  {
    StreamRequestBuilder streamRequestBuilder = new StreamRequestBuilder(new URI(ANY_URI));
    streamRequestBuilder.setHeader("header1", "value1");
    streamRequestBuilder.setHeader("header2", "value2");
    StreamRequest request = streamRequestBuilder.build(
        EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(ANY_ENTITY.getBytes()))));

    Http2Headers headers = NettyRequestAdapter.toHttp2Headers(request);
    Assert.assertNotNull(headers);

    Assert.assertEquals(headers.get("header1"), "value1");
    Assert.assertEquals(headers.get("header2"), "value2");
  }