查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2015 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  
17  /*
18   * Copyright 2014 Twitter, Inc.
19   *
20   * Licensed under the Apache License, Version 2.0 (the "License");
21   * you may not use this file except in compliance with the License.
22   * You may obtain a copy of the License at
23   *
24   *     https://www.apache.org/licenses/LICENSE-2.0
25   *
26   * Unless required by applicable law or agreed to in writing, software
27   * distributed under the License is distributed on an "AS IS" BASIS,
28   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29   * See the License for the specific language governing permissions and
30   * limitations under the License.
31   */
32  package io.netty.handler.codec.http2;
33  
34  import static io.netty.handler.codec.http2.HpackUtil.equalsVariableTime;
35  import static io.netty.util.internal.ObjectUtil.checkNotNull;
36  
37  class HpackHeaderField {
38  
39      // Section 4.1. Calculating Table Size
40      // The additional 32 octets account for an estimated
41      // overhead associated with the structure.
42      static final int HEADER_ENTRY_OVERHEAD = 32;
43  
44      static long sizeOf(CharSequence name, CharSequence value) {
45          return name.length() + value.length() + HEADER_ENTRY_OVERHEAD;
46      }
47  
48      final CharSequence name;
49      final CharSequence value;
50  
51      // This constructor can only be used if name and value are ISO-8859-1 encoded.
52      HpackHeaderField(CharSequence name, CharSequence value) {
53          this.name = checkNotNull(name, "name");
54          this.value = checkNotNull(value, "value");
55      }
56  
57      final int size() {
58          return name.length() + value.length() + HEADER_ENTRY_OVERHEAD;
59      }
60  
61      public final boolean equalsForTest(HpackHeaderField other) {
62          return equalsVariableTime(name, other.name) && equalsVariableTime(value, other.value);
63      }
64  
65      @Override
66      public String toString() {
67          return name + ": " + value;
68      }
69  }