• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.squareup.okhttp.internal.framed;
2 
3 import okio.ByteString;
4 
5 /** HTTP header: the name is an ASCII string, but the value can be UTF-8. */
6 public final class Header {
7   // Special header names defined in the SPDY and HTTP/2 specs.
8   public static final ByteString RESPONSE_STATUS = ByteString.encodeUtf8(":status");
9   public static final ByteString TARGET_METHOD = ByteString.encodeUtf8(":method");
10   public static final ByteString TARGET_PATH = ByteString.encodeUtf8(":path");
11   public static final ByteString TARGET_SCHEME = ByteString.encodeUtf8(":scheme");
12   public static final ByteString TARGET_AUTHORITY = ByteString.encodeUtf8(":authority"); // HTTP/2
13   public static final ByteString TARGET_HOST = ByteString.encodeUtf8(":host"); // spdy/3
14   public static final ByteString VERSION = ByteString.encodeUtf8(":version"); // spdy/3
15 
16   /** Name in case-insensitive ASCII encoding. */
17   public final ByteString name;
18   /** Value in UTF-8 encoding. */
19   public final ByteString value;
20   final int hpackSize;
21 
22   // TODO: search for toLowerCase and consider moving logic here.
Header(String name, String value)23   public Header(String name, String value) {
24     this(ByteString.encodeUtf8(name), ByteString.encodeUtf8(value));
25   }
26 
Header(ByteString name, String value)27   public Header(ByteString name, String value) {
28     this(name, ByteString.encodeUtf8(value));
29   }
30 
Header(ByteString name, ByteString value)31   public Header(ByteString name, ByteString value) {
32     this.name = name;
33     this.value = value;
34     this.hpackSize = 32 + name.size() + value.size();
35   }
36 
equals(Object other)37   @Override public boolean equals(Object other) {
38     if (other instanceof Header) {
39       Header that = (Header) other;
40       return this.name.equals(that.name)
41           && this.value.equals(that.value);
42     }
43     return false;
44   }
45 
hashCode()46   @Override public int hashCode() {
47     int result = 17;
48     result = 31 * result + name.hashCode();
49     result = 31 * result + value.hashCode();
50     return result;
51   }
52 
toString()53   @Override public String toString() {
54     return String.format("%s: %s", name.utf8(), value.utf8());
55   }
56 }
57