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