1 /*
2 * Copyright 2014 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5 * "License"); you may not use this file except in compliance with the License. You may obtain a
6 * 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 distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
13 * the License.
14 */
15 package io.netty5.handler.codec.http2;
16
17 import io.netty5.buffer.api.Buffer;
18 import io.netty5.util.internal.UnstableApi;
19
20 /**
21 * Encodes {@link Http2Headers} into HPACK-encoded headers blocks.
22 */
23 @UnstableApi
24 public interface Http2HeadersEncoder {
25 /**
26 * Configuration related elements for the {@link Http2HeadersEncoder} interface
27 */
28 interface Configuration {
29 /**
30 * Represents the value for
31 * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_HEADER_TABLE_SIZE</a>.
32 * This method should only be called by Netty (not users) as a result of a receiving a {@code SETTINGS} frame.
33 */
34 void maxHeaderTableSize(long max) throws Http2Exception;
35
36 /**
37 * Represents the value for
38 * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_HEADER_TABLE_SIZE</a>.
39 * The initial value returned by this method must be {@link Http2CodecUtil#DEFAULT_HEADER_TABLE_SIZE}.
40 */
41 long maxHeaderTableSize();
42
43 /**
44 * Represents the value for
45 * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_MAX_HEADER_LIST_SIZE</a>.
46 * This method should only be called by Netty (not users) as a result of a receiving a {@code SETTINGS} frame.
47 */
48 void maxHeaderListSize(long max) throws Http2Exception;
49
50 /**
51 * Represents the value for
52 * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_MAX_HEADER_LIST_SIZE</a>.
53 */
54 long maxHeaderListSize();
55 }
56
57 /**
58 * Determine if a header name/value pair is treated as
59 * <a href="https://tools.ietf.org/html/rfc7541#section-7.1.3">sensitive</a>.
60 * If the object can be dynamically modified and shared across multiple connections it may need to be thread safe.
61 */
62 interface SensitivityDetector {
63 /**
64 * Determine if a header {@code name}/{@code value} pair should be treated as
65 * <a href="https://tools.ietf.org/html/rfc7541#section-7.1.3">sensitive</a>.
66 *
67 * @param name The name for the header.
68 * @param value The value of the header.
69 * @return {@code true} if a header {@code name}/{@code value} pair should be treated as
70 * <a href="https://tools.ietf.org/html/rfc7541#section-7.1.3">sensitive</a>.
71 * {@code false} otherwise.
72 */
73 boolean isSensitive(CharSequence name, CharSequence value);
74 }
75
76 /**
77 * Encodes the given headers and writes the output headers block to the given output buffer.
78 *
79 * @param streamId the identifier of the stream for which the headers are encoded.
80 * @param headers the headers to be encoded.
81 * @param buffer the buffer to receive the encoded headers.
82 */
83 void encodeHeaders(int streamId, Http2Headers headers, Buffer buffer) throws Http2Exception;
84
85 /**
86 * Get the {@link Configuration} for this {@link Http2HeadersEncoder}
87 */
88 Configuration configuration();
89
90 /**
91 * Always return {@code false} for {@link SensitivityDetector#isSensitive(CharSequence, CharSequence)}.
92 */
93 SensitivityDetector NEVER_SENSITIVE = (name, value) -> false;
94
95 /**
96 * Always return {@code true} for {@link SensitivityDetector#isSensitive(CharSequence, CharSequence)}.
97 */
98 SensitivityDetector ALWAYS_SENSITIVE = (name, value) -> true;
99 }