View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.hc.core5.http2.impl;
28  
29  import org.apache.hc.core5.http.impl.HttpProcessors;
30  import org.apache.hc.core5.http.protocol.HttpProcessor;
31  import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
32  import org.apache.hc.core5.http.protocol.RequestExpectContinue;
33  import org.apache.hc.core5.http.protocol.RequestUserAgent;
34  import org.apache.hc.core5.http.protocol.ResponseDate;
35  import org.apache.hc.core5.http.protocol.ResponseServer;
36  import org.apache.hc.core5.http2.protocol.H2RequestConnControl;
37  import org.apache.hc.core5.http2.protocol.H2RequestContent;
38  import org.apache.hc.core5.http2.protocol.H2RequestTargetHost;
39  import org.apache.hc.core5.http2.protocol.H2RequestValidateHost;
40  import org.apache.hc.core5.http2.protocol.H2ResponseConnControl;
41  import org.apache.hc.core5.http2.protocol.H2ResponseContent;
42  import org.apache.hc.core5.util.TextUtils;
43  import org.apache.hc.core5.util.VersionInfo;
44  
45  /**
46   * @since 5.0
47   */
48  public final class H2Processors {
49  
50      private final static String SOFTWARE = "Apache-HttpCore";
51  
52      public static HttpProcessorBuilder customServer(final String serverInfo) {
53          return HttpProcessorBuilder.create()
54                  .addAll(
55                          new ResponseDate(),
56                          new ResponseServer(!TextUtils.isBlank(serverInfo) ? serverInfo :
57                                  VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", H2Processors.class)),
58                          new H2ResponseContent(),
59                          new H2ResponseConnControl())
60                  .addAll(
61                          new H2RequestValidateHost());
62      }
63  
64      public static HttpProcessor server(final String serverInfo) {
65          return customServer(serverInfo).build();
66      }
67  
68      public static HttpProcessor server() {
69          return customServer(null).build();
70      }
71  
72      public static HttpProcessorBuilder customClient(final String agentInfo) {
73          return HttpProcessorBuilder.create()
74                  .addAll(
75                          new H2RequestContent(),
76                          new H2RequestTargetHost(),
77                          new H2RequestConnControl(),
78                          new RequestUserAgent(!TextUtils.isBlank(agentInfo) ? agentInfo :
79                                  VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", HttpProcessors.class)),
80                          new RequestExpectContinue());
81      }
82  
83      public static HttpProcessor client(final String agentInfo) {
84          return customClient(agentInfo).build();
85      }
86  
87      public static HttpProcessor client() {
88          return customClient(null).build();
89      }
90  
91  }