View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.transfer;
20  
21  /**
22   * Defines transport property keys specific to HTTP transporters.
23   * These keys can be used to expose additional information about the HTTP transport operation.
24   * Additionally it defines types for the values of these keys, such as {@link HttpVersion} and {@link SslProtocol}.
25   * @see TransferEvent#getTransportProperties()
26   * @since 2.0.21
27   */
28  public final class HttpTransportProperty {
29  
30      private HttpTransportProperty() {
31          // Private constructor to prevent instantiation
32      }
33  
34      /**
35       * Transport property keys specific to HTTP transporters.
36       * @see TransferEvent#getTransportProperties()
37       */
38      public enum Key implements TransferEvent.TransportPropertyKey {
39          /**
40           * Transport property key for HTTP version. Value is a {@link HttpVersion} representing the HTTP version used.
41           */
42          HTTP_VERSION,
43          /**
44           * Transport property key for SSL protocol. Value is a {@link SslProtocol} representing the SSL protocol used.
45           */
46          SSL_PROTOCOL,
47          /**
48           * Transport property key for SSL cipher suite. Value is a String representing the SSL cipher suite used (e.g., "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256").
49           * @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#jsse-cipher-suite-names">JSSE Cipher Suite Names</a>.
50           */
51          SSL_CIPHER_SUITE,
52          /**
53           * Transport property key for content coding (usually compression). Value is a String representing the compression algorithm used (e.g., "gzip", "br", or "zstd")
54           * @see <a href="https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#content-coding">Content Coding Values</a>
55           */
56          CONTENT_CODING,
57      }
58  
59      /**
60       * HTTP version used for the HTTP transport.
61       */
62      public enum HttpVersion {
63          HTTP_1_0("HTTP/1.0"),
64          HTTP_1_1("HTTP/1.1"),
65          HTTP_2("HTTP/2"),
66          HTTP_3("HTTP/3");
67  
68          private final String label;
69  
70          HttpVersion(String label) {
71              this.label = label;
72          }
73  
74          @Override
75          public String toString() {
76              return label;
77          }
78      }
79  
80      /**
81       * SSL protocol including version used for the HTTP transport.
82       */
83      public enum SslProtocol {
84          SSL_3_0("SSLv3"),
85          TLS_1_0("TLSv1"),
86          TLS_1_1("TLSv1.1"),
87          TLS_1_2("TLSv1.2"),
88          TLS_1_3("TLSv1.3");
89  
90          private final String label;
91  
92          SslProtocol(String label) {
93              this.label = label;
94          }
95  
96          @Override
97          public String toString() {
98              return label;
99          }
100 
101         /**
102          * Converts a standard SSL protocol name to the corresponding SslProtocol enum value.
103          *
104          * @param name the standard algorithm name of the SSL protocol (e.g., "TLSv1.2", "TLSv1.3")
105          * @return the corresponding SslProtocol enum value
106          * @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#sslcontext-algorithms">Standard Names for SSLContext Algorithms</a>
107          */
108         public static SslProtocol fromStandardName(String name) {
109             switch (name) {
110                 case "SSLv3":
111                     return SSL_3_0;
112                 case "TLSv1":
113                     return TLS_1_0;
114                 case "TLSv1.1":
115                     return TLS_1_1;
116                 case "TLSv1.2":
117                     return TLS_1_2;
118                 case "TLSv1.3":
119                     return TLS_1_3;
120                 default:
121                     throw new IllegalArgumentException("Unknown SSL protocol: " + name);
122             }
123         }
124     }
125 }