1 //
2 // ========================================================================
3 // Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.spdy.api;
20
21 /**
22 * <p>A container for HEADERS frame metadata and headers.</p>
23 */
24 public class HeadersInfo
25 {
26 /**
27 * <p>Flag that indicates that this {@link HeadersInfo} is the last frame in the stream.</p>
28 *
29 * @see #isClose()
30 * @see #getFlags()
31 */
32 public static final byte FLAG_CLOSE = 1;
33 /**
34 * <p>Flag that indicates that the compression of the stream must be reset.</p>
35 *
36 * @see #isResetCompression()
37 * @see #getFlags()
38 */
39 public static final byte FLAG_RESET_COMPRESSION = 2;
40
41 private final boolean close;
42 private final boolean resetCompression;
43 private final Headers headers;
44
45 /**
46 * <p>Creates a new {@link HeadersInfo} instance with the given headers,
47 * the given close flag and no reset compression flag</p>
48 *
49 * @param headers the {@link Headers}
50 * @param close the value of the close flag
51 */
52 public HeadersInfo(Headers headers, boolean close)
53 {
54 this(headers, close, false);
55 }
56
57 /**
58 * <p>Creates a new {@link HeadersInfo} instance with the given headers,
59 * the given close flag and the given reset compression flag</p>
60 *
61 * @param headers the {@link Headers}
62 * @param close the value of the close flag
63 * @param resetCompression the value of the reset compression flag
64 */
65 public HeadersInfo(Headers headers, boolean close, boolean resetCompression)
66 {
67 this.headers = headers;
68 this.close = close;
69 this.resetCompression = resetCompression;
70 }
71
72 /**
73 * @return the value of the close flag
74 */
75 public boolean isClose()
76 {
77 return close;
78 }
79
80 /**
81 * @return the value of the reset compression flag
82 */
83 public boolean isResetCompression()
84 {
85 return resetCompression;
86 }
87
88 /**
89 * @return the {@link Headers}
90 */
91 public Headers getHeaders()
92 {
93 return headers;
94 }
95
96 /**
97 * @return the close and reset compression flags as integer
98 * @see #FLAG_CLOSE
99 * @see #FLAG_RESET_COMPRESSION
100 */
101 public byte getFlags()
102 {
103 byte flags = isClose() ? FLAG_CLOSE : 0;
104 flags += isResetCompression() ? FLAG_RESET_COMPRESSION : 0;
105 return flags;
106 }
107
108 @Override
109 public String toString()
110 {
111 return String.format("HEADER close=%b %s", close, headers);
112 }
113 }