View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2015 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.http2.frames;
20  
21  import org.eclipse.jetty.http.MetaData;
22  
23  public class HeadersFrame extends Frame
24  {
25      private final int streamId;
26      private final MetaData metaData;
27      private final PriorityFrame priority;
28      private final boolean endStream;
29  
30      /**
31       * <p>Creates a new {@code HEADERS} frame with an unspecified stream {@code id}.</p>
32       * <p>The stream {@code id} will be generated by the implementation while sending
33       * this frame to the other peer.</p>
34       *
35       * @param metaData  the metadata containing HTTP request information
36       * @param priority  the PRIORITY frame associated with this HEADERS frame
37       * @param endStream whether this frame ends the stream
38       */
39      public HeadersFrame(MetaData metaData, PriorityFrame priority, boolean endStream)
40      {
41          this(0, metaData, priority, endStream);
42      }
43  
44      /**
45       * <p>Creates a new {@code HEADERS} frame with the specified stream {@code id}.</p>
46       * <p>{@code HEADERS} frames with a specific stream {@code id} are typically used
47       * in responses to request {@code HEADERS} frames.</p>
48       *
49       * @param streamId  the stream id
50       * @param metaData  the metadata containing HTTP request/response information
51       * @param priority  the PRIORITY frame associated with this HEADERS frame
52       * @param endStream whether this frame ends the stream
53       */
54      public HeadersFrame(int streamId, MetaData metaData, PriorityFrame priority, boolean endStream)
55      {
56          super(FrameType.HEADERS);
57          this.streamId = streamId;
58          this.metaData = metaData;
59          this.priority = priority;
60          this.endStream = endStream;
61      }
62  
63      public int getStreamId()
64      {
65          return streamId;
66      }
67  
68      public MetaData getMetaData()
69      {
70          return metaData;
71      }
72  
73      public PriorityFrame getPriority()
74      {
75          return priority;
76      }
77  
78      public boolean isEndStream()
79      {
80          return endStream;
81      }
82  
83      @Override
84      public String toString()
85      {
86          return String.format("%s#%d{end=%b}", super.toString(), streamId, endStream);
87      }
88  }