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.transport.jdk;
020
021import org.eclipse.aether.ConfigurationProperties;
022import org.eclipse.aether.RepositorySystemSession;
023
024/**
025 * JDK Transport configuration keys.
026 *
027 * @since 2.0.0
028 */
029public final class JdkTransporterConfigurationKeys {
030    private JdkTransporterConfigurationKeys() {}
031
032    private static final String CONFIG_PROPS_PREFIX =
033            ConfigurationProperties.PREFIX_TRANSPORT + JdkTransporterFactory.NAME + ".";
034
035    /**
036     * Use string representation of HttpClient version enum "HTTP_2" or "HTTP_1_1" to set default HTTP protocol to use.
037     *
038     * @configurationSource {@link RepositorySystemSession#getConfigProperties()}
039     * @configurationType {@link java.lang.String}
040     * @configurationDefaultValue {@link #DEFAULT_HTTP_VERSION}
041     * @configurationRepoIdSuffix Yes
042     * @deprecated Use {@link ConfigurationProperties#HTTP_VERSION} instead. This property is kept for backward compatibility and will be removed in future versions.
043     */
044    @Deprecated
045    public static final String CONFIG_PROP_HTTP_VERSION = CONFIG_PROPS_PREFIX + "httpVersion";
046
047    public static final String DEFAULT_HTTP_VERSION = "HTTP_1_1";
048
049    /**
050     * The hard limit of maximum concurrent requests JDK transport can do. This is a workaround for the fact, that in
051     * HTTP/2 mode, JDK HttpClient initializes this value to Integer.MAX_VALUE (!) and lowers it on first response
052     * from the remote server (but it may be too late). See JDK bug
053     * <a href="https://bugs.openjdk.org/browse/JDK-8225647">JDK-8225647</a> for details.
054     *
055     * @configurationSource {@link RepositorySystemSession#getConfigProperties()}
056     * @configurationType {@link java.lang.Integer}
057     * @configurationDefaultValue {@link #DEFAULT_MAX_CONCURRENT_REQUESTS}
058     * @configurationRepoIdSuffix Yes
059     */
060    public static final String CONFIG_PROP_MAX_CONCURRENT_REQUESTS = CONFIG_PROPS_PREFIX + "maxConcurrentRequests";
061
062    public static final int DEFAULT_MAX_CONCURRENT_REQUESTS = 100;
063
064    /**
065     * If enabled, restores the legacy behavior where the transporter's {@link java.net.Authenticator} handed out
066     * the repository (or proxy) credentials to any host that issued an authentication challenge - including hosts
067     * reached by following a redirect off the repository. When disabled (the default), credentials are only
068     * returned when the challenging origin (protocol, host and port) matches the repository base URI, or, for
069     * proxy challenges, the configured proxy address.
070     *
071     * @configurationSource {@link RepositorySystemSession#getConfigProperties()}
072     * @configurationType {@link java.lang.Boolean}
073     * @configurationDefaultValue {@link #DEFAULT_UNSCOPED_AUTHENTICATION}
074     * @configurationRepoIdSuffix Yes
075     * @since 2.0.23
076     */
077    public static final String CONFIG_PROP_UNSCOPED_AUTHENTICATION = CONFIG_PROPS_PREFIX + "unscopedAuthentication";
078
079    public static final boolean DEFAULT_UNSCOPED_AUTHENTICATION = false;
080
081    /**
082     * If enabled (default), operator-configured request headers ({@code aether.transport.http.headers}) and
083     * preemptively applied {@code Authorization} are only sent on requests targeting the repository origin (the
084     * scheme, host and port the repository URL denotes). The JDK {@link java.net.http.HttpClient} re-sends all
085     * user-set headers on every redirect hop it follows - including hops that leave the repository origin - so
086     * with this enabled the transporter configures the client with {@code Redirect.NEVER} and follows redirects
087     * itself, dropping those headers on any hop that leaves the origin. Disable only when a redirect target
088     * legitimately requires the configured headers; disabling restores the JDK client's own redirect handling
089     * ({@code Redirect.NORMAL}) and the legacy header replay.
090     *
091     * @configurationSource {@link RepositorySystemSession#getConfigProperties()}
092     * @configurationType {@link java.lang.Boolean}
093     * @configurationDefaultValue {@link #DEFAULT_ORIGIN_SCOPED_HEADERS}
094     * @configurationRepoIdSuffix Yes
095     * @since 2.0.23
096     */
097    public static final String CONFIG_PROP_ORIGIN_SCOPED_HEADERS = CONFIG_PROPS_PREFIX + "originScopedHeaders";
098
099    public static final boolean DEFAULT_ORIGIN_SCOPED_HEADERS = true;
100}