Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-692

H2 should throw illegal header exception when use Host header as Connection header

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.1
    • 5.2-beta1
    • HttpCore
    • Macos 11.6
      openjdk 11.0.12 2021-07-20

    Description

      I notice org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java:105 throws ProtocolException when header contains Connection. When header contains

      host/upgrade/transfer-encoding header, should it throws ProtocolException eigther?

       

      demo code as below, when I comment Host header, I got 200 response, and when uncomment, got 400 bad request.

      //
      public class HttpUtilTest {
      
          public static void main(String[] args) throws Exception {
      
              HttpContext httpContext = new BasicHttpContext();
              BasicCookieStore cookie = new BasicCookieStore();
              httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookie);
              SimpleHttpRequest request = SimpleRequestBuilder.create(Method.GET)
                  .setUri("https://zzpro2.wmeimob.cn/api/user")
                  .addHeader("User-Agent", "zhenzhu/3.3.3.0 CFNetwork/1128.0.1 Darwin/19.6.0")
                  .addHeader("loading", "false")
                  .addHeader("Accept-Language", "zh-cn")
                  .addHeader("toast", "true")
                  // .addHeader("Host", "zzpro2.wmeimob.cn")
                  .addHeader("Accept-Encoding", "gzip, deflate, br")
                  .build();
      
              SSLContext sslcontext = CipherSuitesUtil.createSslContext();
              final TlsStrategy tlsStrategy = new DefaultClientTlsStrategy(sslcontext, NoopHostnameVerifier.INSTANCE);
              final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder
                  .create()
                  .setTlsStrategy(tlsStrategy)
                  .build();
      
              IOReactorConfig ioConfig =
                  IOReactorConfig.custom()
                      .setSoKeepAlive(true)
                      .setSoTimeout(Timeout.ofMilliseconds(5000))
                      .setIoThreadCount(4)
                      .setSelectInterval(TimeValue.ofMilliseconds(500))
                      .build();
      
              RequestConfig requestConfig =
                  RequestConfig.custom()
                      .setCookieSpec(StandardCookieSpec.RELAXED)
                      .setConnectTimeout(Timeout.ofMilliseconds(5000))
                      .setResponseTimeout(Timeout.ofMilliseconds(5000))
                      .setRedirectsEnabled(true)
                      .setMaxRedirects(10)
                      .build();
      
              HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom()
                  .setDefaultRequestConfig(requestConfig)
                  .setRedirectStrategy(CustomRedirectStrategy.INSTANCE)
                  .setConnectionManager(connectionManager)
                  .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
                  .setIOReactorConfig(ioConfig);
      
              CloseableHttpAsyncClient client = clientBuilder.build();
      
              client.start();
      
              client.execute(request, httpContext, new FutureCallback<>() {
                  @Override
                  public void completed(SimpleHttpResponse result) {
                      try {
                          System.out.println(result);
                      } catch (Exception e) {
      
                      }
                  }
      
                  @Override
                  public void failed(Exception ex) {
                      ex.printStackTrace();
                  }
      
                  @Override
                  public void cancelled() {
                      System.out.println("cancelled");
                  }
              });
      
              Thread.sleep(50 * 1000);
      
              client.close();
          }
      
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            yinwoods yinwoods
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 20m
                1h 20m