001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.transfer;
020
021/**
022 * Defines transport property keys specific to HTTP transporters.
023 * These keys can be used to expose additional information about the HTTP transport operation.
024 * Additionally it defines types for the values of these keys, such as {@link HttpVersion} and {@link SslProtocol}.
025 * @see TransferEvent#getTransportProperties()
026 * @since 2.0.21
027 */
028public final class HttpTransportProperty {
029
030    private HttpTransportProperty() {
031        // Private constructor to prevent instantiation
032    }
033
034    /**
035     * Transport property keys specific to HTTP transporters.
036     * @see TransferEvent#getTransportProperties()
037     */
038    public enum Key implements TransferEvent.TransportPropertyKey {
039        /**
040         * Transport property key for HTTP version. Value is a {@link HttpVersion} representing the HTTP version used.
041         */
042        HTTP_VERSION,
043        /**
044         * Transport property key for SSL protocol. Value is a {@link SslProtocol} representing the SSL protocol used.
045         */
046        SSL_PROTOCOL,
047        /**
048         * 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").
049         * @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>.
050         */
051        SSL_CIPHER_SUITE,
052        /**
053         * Transport property key for content coding (usually compression). Value is a String representing the compression algorithm used (e.g., "gzip", "br", or "zstd")
054         * @see <a href="https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#content-coding">Content Coding Values</a>
055         */
056        CONTENT_CODING,
057    }
058
059    /**
060     * HTTP version used for the HTTP transport.
061     */
062    public enum HttpVersion {
063        HTTP_1_0("HTTP/1.0"),
064        HTTP_1_1("HTTP/1.1"),
065        HTTP_2("HTTP/2"),
066        HTTP_3("HTTP/3");
067
068        private final String label;
069
070        HttpVersion(String label) {
071            this.label = label;
072        }
073
074        @Override
075        public String toString() {
076            return label;
077        }
078    }
079
080    /**
081     * SSL protocol including version used for the HTTP transport.
082     */
083    public enum SslProtocol {
084        SSL_3_0("SSLv3"),
085        TLS_1_0("TLSv1"),
086        TLS_1_1("TLSv1.1"),
087        TLS_1_2("TLSv1.2"),
088        TLS_1_3("TLSv1.3");
089
090        private final String label;
091
092        SslProtocol(String label) {
093            this.label = label;
094        }
095
096        @Override
097        public String toString() {
098            return label;
099        }
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}