View Javadoc
1   /*
2    * Copyright 2020 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  package io.netty.handler.codec.http2;
17  
18  /**
19   * Default implementation of {@link Http2PushPromiseFrame}
20   */
21  public final class DefaultHttp2PushPromiseFrame implements Http2PushPromiseFrame {
22  
23      private Http2FrameStream pushStreamFrame;
24      private final Http2Headers http2Headers;
25      private Http2FrameStream streamFrame;
26      private final int padding;
27      private final int promisedStreamId;
28  
29      public DefaultHttp2PushPromiseFrame(Http2Headers http2Headers) {
30          this(http2Headers, 0);
31      }
32  
33      public DefaultHttp2PushPromiseFrame(Http2Headers http2Headers, int padding) {
34          this(http2Headers, padding, -1);
35      }
36  
37      DefaultHttp2PushPromiseFrame(Http2Headers http2Headers, int padding, int promisedStreamId) {
38          this.http2Headers = http2Headers;
39          this.padding = padding;
40          this.promisedStreamId = promisedStreamId;
41      }
42  
43      @Override
44      public Http2StreamFrame pushStream(Http2FrameStream stream) {
45          pushStreamFrame = stream;
46          return this;
47      }
48  
49      @Override
50      public Http2FrameStream pushStream() {
51          return pushStreamFrame;
52      }
53  
54      @Override
55      public Http2Headers http2Headers() {
56          return http2Headers;
57      }
58  
59      @Override
60      public int padding() {
61          return padding;
62      }
63  
64      @Override
65      public int promisedStreamId() {
66          if (pushStreamFrame != null) {
67              return pushStreamFrame.id();
68          } else {
69              return promisedStreamId;
70          }
71      }
72  
73      @Override
74      public Http2PushPromiseFrame stream(Http2FrameStream stream) {
75          streamFrame = stream;
76          return this;
77      }
78  
79      @Override
80      public Http2FrameStream stream() {
81          return streamFrame;
82      }
83  
84      @Override
85      public String name() {
86          return "PUSH_PROMISE_FRAME";
87      }
88  
89      @Override
90      public String toString() {
91          return "DefaultHttp2PushPromiseFrame{" +
92                  "pushStreamFrame=" + pushStreamFrame +
93                  ", http2Headers=" + http2Headers +
94                  ", streamFrame=" + streamFrame +
95                  ", padding=" + padding +
96                  '}';
97      }
98  }