Repository: netty/netty
File: codec-http3/src/main/java/io/netty/handler/codec/http3/Http3Settings.java (Java)

Code before:
     */
    public static final long HTTP3_SETTINGS_MAX_FIELD_SECTION_SIZE = 0x6;

    /**
     * QPACK blocked streams setting identifier (<b>0x7</b>).
     * <p>
     * Defined in <a href="https://datatracker.ietf.org/doc/html/rfc9204#section-5">
     * RFC 9204, Section 5 (QPACK_BLOCKED_STREAMS)</a> and registered in
     * the <a href="https://www.iana.org/assignments/http3-parameters/http3-parameters.xhtml#settings">
     * HTTP/3 SETTINGS registry (IANA)</a>.
     * <br>
     * Indicates the maximum number of streams that can be blocked waiting for QPACK instructions.
     */
    public static final long HTTP3_SETTINGS_QPACK_BLOCKED_STREAMS = 0x7;

    /**
     * ENABLE_CONNECT_PROTOCOL setting identifier (<b>0x8</b>).
     * <p>
     * Defined and registered in <a href="https://datatracker.ietf.org/doc/html/rfc9220#section-5">
     * RFC 9220, Section 5 (IANA Considerations)</a> and registered in
     * the <a href="https://www.iana.org/assignments/http3-parameters/http3-parameters.xhtml#settings">
     * HTTP/3 SETTINGS registry (IANA)</a>.
     * <br>
     * Enables use of the CONNECT protocol in HTTP/3 when set to 1; disabled when 0.
     */
    public static final long HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x8;

    private static final Long TRUE = 1L;
    private static final Long FALSE = 0L;

    /**
     * Creates a new instance
     */
    public Http3Settings() {
        this.settings = new LongObjectHashMap<>(4);
    }

    /**
     * Creates a new instance with the specified initial capacity.
     *
     * @param initialCapacity initial capacity of the underlying map
     */
    Http3Settings(int initialCapacity) {
        this.settings = new LongObjectHashMap<>(initialCapacity);
    }

    /**
     * Creates a new instance with the specified initial capacity and load factor.
     *
     * @param initialCapacity initial capacity of the underlying map
     * @param loadFactor load factor for the underlying map

Review comment (suggestion):
It breaks ABI compatibility to remove these public constants. We can deprecate them and reference the `Http3SettingIdentifier`, but not remove them.

It's actually odd that revapi isn't complaining about this.

Code after:
     * @param initialCapacity initial capacity of the underlying map
     * @param loadFactor load factor for the underlying map
     */
    Http3Settings(int initialCapacity, float loadFactor) {
        this.settings = new LongObjectHashMap<>(initialCapacity, loadFactor);
    }

    /**
     * Stores a setting value for the specified identifier.
     * <p>
     * The key and value are validated according to the HTTP/3 specification.
     * Reserved HTTP/2 setting identifiers and negative values are not allowed.
     * Ignore any unknown id/key as per <a href="https://www.rfc-editor.org/rfc/rfc9114.html#section-7.2.4-9>rfc9114</a>
     * @param key   the numeric setting identifier
     * @param value the setting value (non-null)
     * @return the previous value associated with the key, or {@code null} if none
     * @throws IllegalArgumentException if the key or value is invalid
     */
    @Nullable
    public Long put(long key, Long value) {

        // When HTTP2 settings identifier present - Throw Error
        if (Http3CodecUtils.isReservedHttp2Setting(key)) {
            throw new IllegalArgumentException("Setting is reserved for HTTP/2: " + key);
        }

        Http3SettingIdentifier identifier = Http3SettingIdentifier.fromId(key);

        // When Non-Standard/Unknown settings identifier identifier present - Ignore
        if (identifier == null) {
            return value;
        }

        //Validation
        verifyStandardSetting(identifier, value);

        return settings.put(key, value);
    }

    /**
     * Returns the value of the specified setting identifier.
     *
     * @param key the numeric setting identifier
     * @return the setting value, or {@code null} if not set
     */
    @Nullable
    public Long get(long key) {
        return settings.get(key);
    }

    /**