View Javadoc
1   /*
2    * Copyright 2015 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * 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 distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package io.netty.handler.codec.http2;
16  
17  import io.netty.channel.ChannelHandlerContext;
18  
19  /**
20   * Provides an extensibility point for users to define the validity of push requests.
21   * @see <a href="https://tools.ietf.org/html/rfc7540#section-8.2">[RFC 7540], Section 8.2</a>.
22   */
23  public interface Http2PromisedRequestVerifier {
24      /**
25       * Determine if a {@link Http2Headers} are authoritative for a particular {@link ChannelHandlerContext}.
26       * @param ctx The context on which the {@code headers} where received on.
27       * @param headers The headers to be verified.
28       * @return {@code true} if the {@code ctx} is authoritative for the {@code headers}, {@code false} otherwise.
29       * @see
30       * <a href="https://tools.ietf.org/html/rfc7540#section-10.1">[RFC 7540], Section 10.1</a>.
31       */
32      boolean isAuthoritative(ChannelHandlerContext ctx, Http2Headers headers);
33  
34      /**
35       * Determine if a request is cacheable.
36       * @param headers The headers for a push request.
37       * @return {@code true} if the request associated with {@code headers} is known to be cacheable,
38       * {@code false} otherwise.
39       * @see <a href="https://tools.ietf.org/html/rfc7231#section-4.2.3">[RFC 7231], Section 4.2.3</a>.
40       */
41      boolean isCacheable(Http2Headers headers);
42  
43      /**
44       * Determine if a request is safe.
45       * @param headers The headers for a push request.
46       * @return {@code true} if the request associated with {@code headers} is known to be safe,
47       * {@code false} otherwise.
48       * @see <a href="https://tools.ietf.org/html/rfc7231#section-4.2.1">[RFC 7231], Section 4.2.1</a>.
49       */
50      boolean isSafe(Http2Headers headers);
51  
52      /**
53       * A default implementation of {@link Http2PromisedRequestVerifier} which always returns positive responses for
54       * all verification challenges.
55       */
56      Http2PromisedRequestVerifier ALWAYS_VERIFY = new Http2PromisedRequestVerifier() {
57          @Override
58          public boolean isAuthoritative(ChannelHandlerContext ctx, Http2Headers headers) {
59              return true;
60          }
61  
62          @Override
63          public boolean isCacheable(Http2Headers headers) {
64              return true;
65          }
66  
67          @Override
68          public boolean isSafe(Http2Headers headers) {
69              return true;
70          }
71      };
72  }