1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package jdk.incubator.http.internal.hpack;
26
27 import java.nio.ByteBuffer;
28
29 /**
30 * Delivers results of the {@link Decoder#decode(ByteBuffer, boolean,
31 * DecodingCallback) decoding operation}.
32 *
33 * <p> Methods of the callback are never called by a decoder with any of the
34 * arguments being {@code null}.
35 *
36 * @apiNote
37 *
38 * <p> The callback provides methods for all possible <a
39 * href="https://tools.ietf.org/html/rfc7541#section-6">binary
40 * representations</a>. This could be useful for implementing an intermediary,
41 * logging, debugging, etc.
42 *
43 * <p> The callback is an interface in order to interoperate with lambdas (in
44 * the most common use case):
45 * <pre>{@code
46 * DecodingCallback callback = (name, value) -> System.out.println(name + ", " + value);
47 * }</pre>
48 *
49 * <p> Names and values are {@link CharSequence}s rather than {@link String}s in
50 * order to allow users to decide whether or not they need to create objects. A
51 * {@code CharSequence} might be used in-place, for example, to be appended to
52 * an {@link Appendable} (e.g. {@link StringBuilder}) and then discarded.
53 *
54 * <p> That said, if a passed {@code CharSequence} needs to outlast the method
55 * call, it needs to be copied.
56 *
57 * @since 9
58 */
59 @FunctionalInterface
60 public interface DecodingCallback {
61
81 *
82 * <p> It is required that intermediaries MUST use the {@linkplain
83 * Encoder#header(CharSequence, CharSequence, boolean) same representation}
84 * for encoding this header field in order to protect its value which is not
85 * to be put at risk by compressing it.
86 *
87 * @implSpec
88 *
89 * <p> The default implementation invokes {@code onDecoded(name, value)}.
90 *
91 * @param name
92 * header name
93 * @param value
94 * header value
95 * @param sensitive
96 * whether or not the value is sensitive
97 *
98 * @see #onLiteralNeverIndexed(int, CharSequence, CharSequence, boolean)
99 * @see #onLiteralNeverIndexed(CharSequence, boolean, CharSequence, boolean)
100 */
101 default void onDecoded(CharSequence name, CharSequence value,
102 boolean sensitive) {
103 onDecoded(name, value);
104 }
105
106 /**
107 * An <a href="https://tools.ietf.org/html/rfc7541#section-6.1">Indexed
108 * Header Field</a> decoded.
109 *
110 * @implSpec
111 *
112 * <p> The default implementation invokes
113 * {@code onDecoded(name, value, false)}.
114 *
115 * @param index
116 * index of an entry in the table
117 * @param name
118 * header name
119 * @param value
120 * header value
121 */
125
126 /**
127 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.2">Literal
128 * Header Field without Indexing</a> decoded, where a {@code name} was
129 * referred by an {@code index}.
130 *
131 * @implSpec
132 *
133 * <p> The default implementation invokes
134 * {@code onDecoded(name, value, false)}.
135 *
136 * @param index
137 * index of an entry in the table
138 * @param name
139 * header name
140 * @param value
141 * header value
142 * @param valueHuffman
143 * if the {@code value} was Huffman encoded
144 */
145 default void onLiteral(int index, CharSequence name,
146 CharSequence value, boolean valueHuffman) {
147 onDecoded(name, value, false);
148 }
149
150 /**
151 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.2">Literal
152 * Header Field without Indexing</a> decoded, where both a {@code name} and
153 * a {@code value} were literal.
154 *
155 * @implSpec
156 *
157 * <p> The default implementation invokes
158 * {@code onDecoded(name, value, false)}.
159 *
160 * @param name
161 * header name
162 * @param nameHuffman
163 * if the {@code name} was Huffman encoded
164 * @param value
165 * header value
166 * @param valueHuffman
167 * if the {@code value} was Huffman encoded
168 */
169 default void onLiteral(CharSequence name, boolean nameHuffman,
170 CharSequence value, boolean valueHuffman) {
171 onDecoded(name, value, false);
172 }
173
174 /**
175 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.3">Literal
176 * Header Field Never Indexed</a> decoded, where a {@code name}
177 * was referred by an {@code index}.
178 *
179 * @implSpec
180 *
181 * <p> The default implementation invokes
182 * {@code onDecoded(name, value, true)}.
183 *
184 * @param index
185 * index of an entry in the table
186 * @param name
187 * header name
188 * @param value
189 * header value
190 * @param valueHuffman
191 * if the {@code value} was Huffman encoded
192 */
193 default void onLiteralNeverIndexed(int index, CharSequence name,
194 CharSequence value,
195 boolean valueHuffman) {
196 onDecoded(name, value, true);
197 }
198
199 /**
200 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.3">Literal
201 * Header Field Never Indexed</a> decoded, where both a {@code
202 * name} and a {@code value} were literal.
203 *
204 * @implSpec
205 *
206 * <p> The default implementation invokes
207 * {@code onDecoded(name, value, true)}.
208 *
209 * @param name
210 * header name
211 * @param nameHuffman
212 * if the {@code name} was Huffman encoded
213 * @param value
214 * header value
215 * @param valueHuffman
216 * if the {@code value} was Huffman encoded
217 */
218 default void onLiteralNeverIndexed(CharSequence name, boolean nameHuffman,
219 CharSequence value, boolean valueHuffman) {
220 onDecoded(name, value, true);
221 }
222
223 /**
224 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.1">Literal
225 * Header Field with Incremental Indexing</a> decoded, where a {@code name}
226 * was referred by an {@code index}.
227 *
228 * @implSpec
229 *
230 * <p> The default implementation invokes
231 * {@code onDecoded(name, value, false)}.
232 *
233 * @param index
234 * index of an entry in the table
235 * @param name
236 * header name
237 * @param value
238 * header value
239 * @param valueHuffman
240 * if the {@code value} was Huffman encoded
241 */
242 default void onLiteralWithIndexing(int index,
243 CharSequence name,
244 CharSequence value, boolean valueHuffman) {
245 onDecoded(name, value, false);
246 }
247
248 /**
249 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.1">Literal
250 * Header Field with Incremental Indexing</a> decoded, where both a {@code
251 * name} and a {@code value} were literal.
252 *
253 * @implSpec
254 *
255 * <p> The default implementation invokes
256 * {@code onDecoded(name, value, false)}.
257 *
258 * @param name
259 * header name
260 * @param nameHuffman
261 * if the {@code name} was Huffman encoded
262 * @param value
263 * header value
264 * @param valueHuffman
265 * if the {@code value} was Huffman encoded
266 */
267 default void onLiteralWithIndexing(CharSequence name, boolean nameHuffman,
268 CharSequence value, boolean valueHuffman) {
269 onDecoded(name, value, false);
270 }
271
272 /**
273 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.3">Dynamic Table
274 * Size Update</a> decoded.
275 *
276 * @implSpec
277 *
278 * <p> The default implementation does nothing.
279 *
280 * @param capacity
281 * new capacity of the header table
282 */
283 default void onSizeUpdate(int capacity) { }
284 }
|
1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package jdk.incubator.http.internal.hpack;
26
27 import java.nio.ByteBuffer;
28
29 /**
30 * Delivers results of the {@link Decoder#decode(ByteBuffer, boolean,
31 * DecodingCallback) decoding operation}.
32 *
33 * <p> Methods of the callback are never called by a decoder with any of the
34 * arguments being {@code null}.
35 *
36 * @apiNote
37 *
38 * <p> The callback provides methods for all possible
39 * <a href="https://tools.ietf.org/html/rfc7541#section-6">binary representations</a>.
40 * This could be useful for implementing an intermediary, logging, debugging,
41 * etc.
42 *
43 * <p> The callback is an interface in order to interoperate with lambdas (in
44 * the most common use case):
45 * <pre>{@code
46 * DecodingCallback callback = (name, value) -> System.out.println(name + ", " + value);
47 * }</pre>
48 *
49 * <p> Names and values are {@link CharSequence}s rather than {@link String}s in
50 * order to allow users to decide whether or not they need to create objects. A
51 * {@code CharSequence} might be used in-place, for example, to be appended to
52 * an {@link Appendable} (e.g. {@link StringBuilder}) and then discarded.
53 *
54 * <p> That said, if a passed {@code CharSequence} needs to outlast the method
55 * call, it needs to be copied.
56 *
57 * @since 9
58 */
59 @FunctionalInterface
60 public interface DecodingCallback {
61
81 *
82 * <p> It is required that intermediaries MUST use the {@linkplain
83 * Encoder#header(CharSequence, CharSequence, boolean) same representation}
84 * for encoding this header field in order to protect its value which is not
85 * to be put at risk by compressing it.
86 *
87 * @implSpec
88 *
89 * <p> The default implementation invokes {@code onDecoded(name, value)}.
90 *
91 * @param name
92 * header name
93 * @param value
94 * header value
95 * @param sensitive
96 * whether or not the value is sensitive
97 *
98 * @see #onLiteralNeverIndexed(int, CharSequence, CharSequence, boolean)
99 * @see #onLiteralNeverIndexed(CharSequence, boolean, CharSequence, boolean)
100 */
101 default void onDecoded(CharSequence name,
102 CharSequence value,
103 boolean sensitive) {
104 onDecoded(name, value);
105 }
106
107 /**
108 * An <a href="https://tools.ietf.org/html/rfc7541#section-6.1">Indexed
109 * Header Field</a> decoded.
110 *
111 * @implSpec
112 *
113 * <p> The default implementation invokes
114 * {@code onDecoded(name, value, false)}.
115 *
116 * @param index
117 * index of an entry in the table
118 * @param name
119 * header name
120 * @param value
121 * header value
122 */
126
127 /**
128 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.2">Literal
129 * Header Field without Indexing</a> decoded, where a {@code name} was
130 * referred by an {@code index}.
131 *
132 * @implSpec
133 *
134 * <p> The default implementation invokes
135 * {@code onDecoded(name, value, false)}.
136 *
137 * @param index
138 * index of an entry in the table
139 * @param name
140 * header name
141 * @param value
142 * header value
143 * @param valueHuffman
144 * if the {@code value} was Huffman encoded
145 */
146 default void onLiteral(int index,
147 CharSequence name,
148 CharSequence value,
149 boolean valueHuffman) {
150 onDecoded(name, value, false);
151 }
152
153 /**
154 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.2">Literal
155 * Header Field without Indexing</a> decoded, where both a {@code name} and
156 * a {@code value} were literal.
157 *
158 * @implSpec
159 *
160 * <p> The default implementation invokes
161 * {@code onDecoded(name, value, false)}.
162 *
163 * @param name
164 * header name
165 * @param nameHuffman
166 * if the {@code name} was Huffman encoded
167 * @param value
168 * header value
169 * @param valueHuffman
170 * if the {@code value} was Huffman encoded
171 */
172 default void onLiteral(CharSequence name,
173 boolean nameHuffman,
174 CharSequence value,
175 boolean valueHuffman) {
176 onDecoded(name, value, false);
177 }
178
179 /**
180 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.3">Literal
181 * Header Field Never Indexed</a> decoded, where a {@code name}
182 * was referred by an {@code index}.
183 *
184 * @implSpec
185 *
186 * <p> The default implementation invokes
187 * {@code onDecoded(name, value, true)}.
188 *
189 * @param index
190 * index of an entry in the table
191 * @param name
192 * header name
193 * @param value
194 * header value
195 * @param valueHuffman
196 * if the {@code value} was Huffman encoded
197 */
198 default void onLiteralNeverIndexed(int index,
199 CharSequence name,
200 CharSequence value,
201 boolean valueHuffman) {
202 onDecoded(name, value, true);
203 }
204
205 /**
206 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.3">Literal
207 * Header Field Never Indexed</a> decoded, where both a {@code
208 * name} and a {@code value} were literal.
209 *
210 * @implSpec
211 *
212 * <p> The default implementation invokes
213 * {@code onDecoded(name, value, true)}.
214 *
215 * @param name
216 * header name
217 * @param nameHuffman
218 * if the {@code name} was Huffman encoded
219 * @param value
220 * header value
221 * @param valueHuffman
222 * if the {@code value} was Huffman encoded
223 */
224 default void onLiteralNeverIndexed(CharSequence name,
225 boolean nameHuffman,
226 CharSequence value,
227 boolean valueHuffman) {
228 onDecoded(name, value, true);
229 }
230
231 /**
232 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.1">Literal
233 * Header Field with Incremental Indexing</a> decoded, where a {@code name}
234 * was referred by an {@code index}.
235 *
236 * @implSpec
237 *
238 * <p> The default implementation invokes
239 * {@code onDecoded(name, value, false)}.
240 *
241 * @param index
242 * index of an entry in the table
243 * @param name
244 * header name
245 * @param value
246 * header value
247 * @param valueHuffman
248 * if the {@code value} was Huffman encoded
249 */
250 default void onLiteralWithIndexing(int index,
251 CharSequence name,
252 CharSequence value,
253 boolean valueHuffman) {
254 onDecoded(name, value, false);
255 }
256
257 /**
258 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.2.1">Literal
259 * Header Field with Incremental Indexing</a> decoded, where both a {@code
260 * name} and a {@code value} were literal.
261 *
262 * @implSpec
263 *
264 * <p> The default implementation invokes
265 * {@code onDecoded(name, value, false)}.
266 *
267 * @param name
268 * header name
269 * @param nameHuffman
270 * if the {@code name} was Huffman encoded
271 * @param value
272 * header value
273 * @param valueHuffman
274 * if the {@code value} was Huffman encoded
275 */
276 default void onLiteralWithIndexing(CharSequence name,
277 boolean nameHuffman,
278 CharSequence value,
279 boolean valueHuffman) {
280 onDecoded(name, value, false);
281 }
282
283 /**
284 * A <a href="https://tools.ietf.org/html/rfc7541#section-6.3">Dynamic Table
285 * Size Update</a> decoded.
286 *
287 * @implSpec
288 *
289 * <p> The default implementation does nothing.
290 *
291 * @param capacity
292 * new capacity of the header table
293 */
294 default void onSizeUpdate(int capacity) { }
295 }
|