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.netty5.handler.codec.http2;
16
17 import io.netty5.channel.ChannelHandlerContext;
18 import io.netty5.util.internal.UnstableApi;
19
20 /**
21 * Provides an extensibility point for users to define the validity of push requests.
22 * @see <a href="https://tools.ietf.org/html/rfc7540#section-8.2">[RFC 7540], Section 8.2</a>.
23 */
24 @UnstableApi
25 public interface Http2PromisedRequestVerifier {
26 /**
27 * Determine if a {@link Http2Headers} are authoritative for a particular {@link ChannelHandlerContext}.
28 * @param ctx The context on which the {@code headers} where received on.
29 * @param headers The headers to be verified.
30 * @return {@code true} if the {@code ctx} is authoritative for the {@code headers}, {@code false} otherwise.
31 * @see
32 * <a href="https://tools.ietf.org/html/rfc7540#section-10.1">[RFC 7540], Section 10.1</a>.
33 */
34 boolean isAuthoritative(ChannelHandlerContext ctx, Http2Headers headers);
35
36 /**
37 * Determine if a request is cacheable.
38 * @param headers The headers for a push request.
39 * @return {@code true} if the request associated with {@code headers} is known to be cacheable,
40 * {@code false} otherwise.
41 * @see <a href="https://tools.ietf.org/html/rfc7231#section-4.2.3">[RFC 7231], Section 4.2.3</a>.
42 */
43 boolean isCacheable(Http2Headers headers);
44
45 /**
46 * Determine if a request is safe.
47 * @param headers The headers for a push request.
48 * @return {@code true} if the request associated with {@code headers} is known to be safe,
49 * {@code false} otherwise.
50 * @see <a href="https://tools.ietf.org/html/rfc7231#section-4.2.1">[RFC 7231], Section 4.2.1</a>.
51 */
52 boolean isSafe(Http2Headers headers);
53
54 /**
55 * A default implementation of {@link Http2PromisedRequestVerifier} which always returns positive responses for
56 * all verification challenges.
57 */
58 Http2PromisedRequestVerifier ALWAYS_VERIFY = new Http2PromisedRequestVerifier() {
59 @Override
60 public boolean isAuthoritative(ChannelHandlerContext ctx, Http2Headers headers) {
61 return true;
62 }
63
64 @Override
65 public boolean isCacheable(Http2Headers headers) {
66 return true;
67 }
68
69 @Override
70 public boolean isSafe(Http2Headers headers) {
71 return true;
72 }
73 };
74 }