1 /*
2 * Copyright 2025 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty.handler.codec.http3;
17
18 import org.jetbrains.annotations.Nullable;
19
20 import java.util.Arrays;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.function.Function;
25 import java.util.stream.Collectors;
26
27 public enum Http3SettingIdentifier {
28
29 /**
30 * QPACK maximum table capacity setting identifier (<b>0x1</b>).
31 * <p>
32 * Defined in <a href="https://datatracker.ietf.org/doc/html/rfc9204#section-5">
33 * RFC 9204, Section 5 (SETTINGS_QPACK_MAX_TABLE_CAPACITY)</a> and registered in
34 * the <a href="https://www.iana.org/assignments/http3-parameters/http3-parameters.xhtml#settings">
35 * HTTP/3 SETTINGS registry (IANA)</a>.
36 * <br>
37 * Controls the maximum size of the dynamic table used by QPACK.
38 */
39 HTTP3_SETTINGS_QPACK_MAX_TABLE_CAPACITY(0x1),
40
41 /**
42 * Maximum field section size setting identifier (<b>0x6</b>).
43 * <p>
44 * Defined in <a href="https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.4.1">
45 * RFC 9114, Section 7.2.4.1 (SETTINGS_MAX_FIELD_SECTION_SIZE)</a> , also referenced
46 * in the <a href="https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.4.1">
47 * HTTP/3 SETTINGS registry (RFC 9114, Section 7.2.4.1)</a> and registered in
48 * the <a href="https://www.iana.org/assignments/http3-parameters/http3-parameters.xhtml#settings">
49 * HTTP/3 SETTINGS registry (IANA)</a>.
50 * <br>
51 * Specifies the upper bound on the total size of HTTP field sections accepted by a peer.
52 */
53 HTTP3_SETTINGS_MAX_FIELD_SECTION_SIZE(0x6),
54
55 /**
56 * QPACK blocked streams setting identifier (<b>0x7</b>).
57 * <p>
58 * Defined in <a href="https://datatracker.ietf.org/doc/html/rfc9204#section-5">
59 * RFC 9204, Section 5 (SETTINGS_QPACK_BLOCKED_STREAMS)</a> and registered in
60 * the <a href="https://www.iana.org/assignments/http3-parameters/http3-parameters.xhtml#settings">
61 * HTTP/3 SETTINGS registry (IANA)</a>.
62 * <br>
63 * Indicates the maximum number of streams that can be blocked waiting for QPACK instructions.
64 */
65 HTTP3_SETTINGS_QPACK_BLOCKED_STREAMS(0x7),
66
67 /**
68 * ENABLE_CONNECT_PROTOCOL setting identifier (<b>0x8</b>).
69 * <p>
70 * Defined and registered in <a href="https://datatracker.ietf.org/doc/html/rfc9220#section-5">
71 * RFC 9220, Section 5 (IANA Considerations)</a> and registered in
72 * the <a href="https://www.iana.org/assignments/http3-parameters/http3-parameters.xhtml#settings">
73 * HTTP/3 SETTINGS registry (IANA)</a>.
74 * <br>
75 * Enables use of the CONNECT protocol in HTTP/3 when set to 1; disabled when 0.
76 */
77 HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL(0x8),
78
79 /**
80 * ENABLE_H3_DATAGRAM setting identifier (<b>0x8</b>).
81 * <p>
82 * Defined and registered in <a href="https://datatracker.ietf.org/doc/html/rfc9297#name-http-3-setting">
83 * RFC 9220, Section 5 (IANA Considerations)</a> and registered in
84 * the <a href="https://www.iana.org/assignments/http3-parameters/http3-parameters.xhtml#settings">
85 * HTTP/3 SETTINGS registry (IANA)</a>.
86 * <br>
87 * Enables use of the CONNECT protocol in HTTP/3 when set to 1; disabled when 0.
88 */
89 HTTP3_SETTINGS_H3_DATAGRAM(0x33);
90
91 private final long id;
92
93 private static final Map<Long, Http3SettingIdentifier> LOOKUP = Collections.unmodifiableMap(
94 Arrays.stream(values()).collect(Collectors.toMap(Http3SettingIdentifier::id, Function.identity()))
95 );
96
97 Http3SettingIdentifier(long id) {
98 this.id = id;
99 }
100
101 /**
102 * Returns the Identifier of {@link Http3SettingIdentifier}
103 * for example:
104 * SETTINGS_QPACK_MAX_TABLE_CAPACITY = 0x1 = 1 in the settings frame
105 * <br>
106 * @return long(represented as hexadecimal above) value of the Identifier
107 */
108 public long id() {
109 return id;
110 }
111
112 /**
113 * Returns {@link Http3SettingIdentifier}
114 * @param id
115 * @return {@link Http3SettingIdentifier} enum which represents @param id, null otherwise
116 */
117 @Nullable
118 public static Http3SettingIdentifier fromId(long id) {
119 return LOOKUP.get(id);
120 }
121 }