查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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  
16  package io.netty.handler.codec.http2;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.util.internal.UnstableApi;
20  
21  /**
22   * Encodes {@link Http2Headers} into HPACK-encoded headers blocks.
23   */
24  @UnstableApi
25  public interface Http2HeadersEncoder {
26      /**
27       * Configuration related elements for the {@link Http2HeadersEncoder} interface
28       */
29      interface Configuration {
30          /**
31           * Represents the value for
32           * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_HEADER_TABLE_SIZE</a>.
33           * This method should only be called by Netty (not users) as a result of a receiving a {@code SETTINGS} frame.
34           */
35          void maxHeaderTableSize(long max) throws Http2Exception;
36  
37          /**
38           * Represents the value for
39           * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_HEADER_TABLE_SIZE</a>.
40           * The initial value returned by this method must be {@link Http2CodecUtil#DEFAULT_HEADER_TABLE_SIZE}.
41           */
42          long maxHeaderTableSize();
43  
44          /**
45           * Represents the value for
46           * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_MAX_HEADER_LIST_SIZE</a>.
47           * This method should only be called by Netty (not users) as a result of a receiving a {@code SETTINGS} frame.
48           */
49          void maxHeaderListSize(long max) throws Http2Exception;
50  
51          /**
52           * Represents the value for
53           * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_MAX_HEADER_LIST_SIZE</a>.
54           */
55          long maxHeaderListSize();
56      }
57  
58      /**
59       * Determine if a header name/value pair is treated as
60       * <a href="https://tools.ietf.org/html/rfc7541#section-7.1.3">sensitive</a>.
61       * If the object can be dynamically modified and shared across multiple connections it may need to be thread safe.
62       */
63      interface SensitivityDetector {
64          /**
65           * Determine if a header {@code name}/{@code value} pair should be treated as
66           * <a href="https://tools.ietf.org/html/rfc7541#section-7.1.3">sensitive</a>.
67           *
68           * @param name The name for the header.
69           * @param value The value of the header.
70           * @return {@code true} if a header {@code name}/{@code value} pair should be treated as
71           * <a href="https://tools.ietf.org/html/rfc7541#section-7.1.3">sensitive</a>.
72           * {@code false} otherwise.
73           */
74          boolean isSensitive(CharSequence name, CharSequence value);
75      }
76  
77      /**
78       * Encodes the given headers and writes the output headers block to the given output buffer.
79       *
80       * @param streamId  the identifier of the stream for which the headers are encoded.
81       * @param headers the headers to be encoded.
82       * @param buffer the buffer to receive the encoded headers.
83       */
84      void encodeHeaders(int streamId, Http2Headers headers, ByteBuf buffer) throws Http2Exception;
85  
86      /**
87       * Get the {@link Configuration} for this {@link Http2HeadersEncoder}
88       */
89      Configuration configuration();
90  
91      /**
92       * Always return {@code false} for {@link SensitivityDetector#isSensitive(CharSequence, CharSequence)}.
93       */
94      SensitivityDetector NEVER_SENSITIVE = new SensitivityDetector() {
95          @Override
96          public boolean isSensitive(CharSequence name, CharSequence value) {
97              return false;
98          }
99      };
100 
101     /**
102      * Always return {@code true} for {@link SensitivityDetector#isSensitive(CharSequence, CharSequence)}.
103      */
104     SensitivityDetector ALWAYS_SENSITIVE = new SensitivityDetector() {
105         @Override
106         public boolean isSensitive(CharSequence name, CharSequence value) {
107             return true;
108         }
109     };
110 }