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 import java.util.concurrent.TimeUnit;
22
23 import org.eclipse.jetty.util.Fields;
24
25 /**
26 * <p>A container for HEADERS frame metadata and headers.</p>
27 */
28 public class HeadersInfo extends Info
29 {
30 /**
31 * <p>Flag that indicates that this {@link HeadersInfo} is the last frame in the stream.</p>
32 *
33 * @see #isClose()
34 * @see #getFlags()
35 */
36 public static final byte FLAG_CLOSE = 1;
37 /**
38 * <p>Flag that indicates that the compression of the stream must be reset.</p>
39 *
40 * @see #isResetCompression()
41 * @see #getFlags()
42 */
43 public static final byte FLAG_RESET_COMPRESSION = 2;
44
45 private final boolean close;
46 private final boolean resetCompression;
47 private final Fields headers;
48
49 /**
50 * <p>Creates a new {@link HeadersInfo} instance with the given headers, the given close flag and no reset
51 * compression flag</p>
52 *
53 * @param headers the {@link Fields}
54 * @param close the value of the close flag
55 */
56 public HeadersInfo(Fields headers, boolean close)
57 {
58 this(headers, close, false);
59 }
60
61 /**
62 * <p>Creates a new {@link HeadersInfo} instance with the given headers, the given close flag and the given reset
63 * compression flag</p>
64 *
65 * @param headers the {@link Fields}
66 * @param close the value of the close flag
67 * @param resetCompression the value of the reset compression flag
68 */
69 public HeadersInfo(Fields headers, boolean close, boolean resetCompression)
70 {
71 this.headers = headers;
72 this.close = close;
73 this.resetCompression = resetCompression;
74 }
75
76 /**
77 * <p>Creates a new {@link HeadersInfo} instance with the given headers, the given close flag and the given reset
78 * compression flag</p>
79 *
80 * @param timeout the operation's timeout
81 * @param unit the timeout's unit
82 * @param headers the {@link Fields}
83 * @param close the value of the close flag
84 * @param resetCompression the value of the reset compression flag
85 */
86 public HeadersInfo(long timeout, TimeUnit unit, boolean close, boolean resetCompression, Fields headers)
87 {
88 super(timeout, unit);
89 this.close = close;
90 this.resetCompression = resetCompression;
91 this.headers = headers;
92 }
93
94 /**
95 * @return the value of the close flag
96 */
97 public boolean isClose()
98 {
99 return close;
100 }
101
102 /**
103 * @return the value of the reset compression flag
104 */
105 public boolean isResetCompression()
106 {
107 return resetCompression;
108 }
109
110 /**
111 * @return the {@link Fields}
112 */
113 public Fields getHeaders()
114 {
115 return headers;
116 }
117
118 /**
119 * @return the close and reset compression flags as integer
120 * @see #FLAG_CLOSE
121 * @see #FLAG_RESET_COMPRESSION
122 */
123 public byte getFlags()
124 {
125 byte flags = isClose() ? FLAG_CLOSE : 0;
126 flags += isResetCompression() ? FLAG_RESET_COMPRESSION : 0;
127 return flags;
128 }
129
130 @Override
131 public String toString()
132 {
133 return String.format("HEADER close=%b %s", close, headers);
134 }
135 }