|
| 1 | +/* |
| 2 | + * ==================================================================== |
| 3 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + * or more contributor license agreements. See the NOTICE file |
| 5 | + * distributed with this work for additional information |
| 6 | + * regarding copyright ownership. The ASF licenses this file |
| 7 | + * to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance |
| 9 | + * with the License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, |
| 14 | + * software distributed under the License is distributed on an |
| 15 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + * KIND, either express or implied. See the License for the |
| 17 | + * specific language governing permissions and limitations |
| 18 | + * under the License. |
| 19 | + * ==================================================================== |
| 20 | + * |
| 21 | + * This software consists of voluntary contributions made by many |
| 22 | + * individuals on behalf of the Apache Software Foundation. For more |
| 23 | + * information on the Apache Software Foundation, please see |
| 24 | + * <http://www.apache.org/>. |
| 25 | + * |
| 26 | + */ |
| 27 | +package org.apache.hc.core5.http2; |
| 28 | + |
| 29 | +import java.util.concurrent.ConcurrentHashMap; |
| 30 | +import java.util.concurrent.ConcurrentMap; |
| 31 | + |
| 32 | +/** |
| 33 | + * Errors codes defined by HTTP/2 specification. |
| 34 | + * |
| 35 | + * @since 5.0 |
| 36 | + */ |
| 37 | +public enum H2Error { |
| 38 | + |
| 39 | + /** |
| 40 | + * Graceful shutdown |
| 41 | + * <p> |
| 42 | + * The associated condition is not as a result of an error. |
| 43 | + */ |
| 44 | + NO_ERROR (0x00), |
| 45 | + |
| 46 | + /** |
| 47 | + * Protocol error detected |
| 48 | + * <p> |
| 49 | + * The endpoint detected an unspecific protocol error. This error is for use when a more |
| 50 | + * specific error code is not available |
| 51 | + */ |
| 52 | + PROTOCOL_ERROR (0x01), |
| 53 | + |
| 54 | + /** |
| 55 | + * Implementation fault |
| 56 | + * <p> |
| 57 | + * The endpoint encountered an unexpected internal error. |
| 58 | + */ |
| 59 | + INTERNAL_ERROR (0x02), |
| 60 | + |
| 61 | + /** |
| 62 | + * Flow control limits exceeded. |
| 63 | + * <p> |
| 64 | + * The endpoint detected that its peer violated the flow control protocol. |
| 65 | + */ |
| 66 | + FLOW_CONTROL_ERROR (0x03), |
| 67 | + |
| 68 | + /** |
| 69 | + * Settings not acknowledged. |
| 70 | + * <p> |
| 71 | + * The endpoint sent a SETTINGS frame, but did not receive a response in a timely manner. |
| 72 | + */ |
| 73 | + SETTINGS_TIMEOUT (0x04), |
| 74 | + |
| 75 | + /** |
| 76 | + * Frame received for closed stream. |
| 77 | + * <p> |
| 78 | + * The endpoint received a frame after a stream was half closed. |
| 79 | + */ |
| 80 | + STREAM_CLOSED (0x05), |
| 81 | + |
| 82 | + /** |
| 83 | + * Frame size incorrect. |
| 84 | + * <p> |
| 85 | + * The endpoint received a frame with an invalid size. |
| 86 | + */ |
| 87 | + FRAME_SIZE_ERROR (0x06), |
| 88 | + |
| 89 | + /** |
| 90 | + * Stream not processed |
| 91 | + * <p> |
| 92 | + * The endpoint refuses the stream prior to performing any application processing. |
| 93 | + */ |
| 94 | + REFUSED_STREAM (0x07), |
| 95 | + |
| 96 | + /** |
| 97 | + * Stream canceled. |
| 98 | + * <p> |
| 99 | + * Used by the endpoint to indicate that the stream is no longer needed |
| 100 | + */ |
| 101 | + CANCEL (0x08), |
| 102 | + |
| 103 | + /** |
| 104 | + * Compression state not updated. |
| 105 | + * <p> |
| 106 | + * The endpoint is unable to maintain the header compression context for the connection. |
| 107 | + */ |
| 108 | + COMPRESSION_ERROR (0x09), |
| 109 | + |
| 110 | + /** |
| 111 | + * TCP connection error. |
| 112 | + * <p> |
| 113 | + * The connection established in response to a CONNECT request was reset or abnormally closed. |
| 114 | + */ |
| 115 | + CONNECT_ERROR (0x0a), |
| 116 | + |
| 117 | + /** |
| 118 | + * Processing capacity exceeded. |
| 119 | + * <p> |
| 120 | + * The endpoint detected that its peer is exhibiting a behavior that might be generating |
| 121 | + * excessive load. |
| 122 | + */ |
| 123 | + ENHANCE_YOUR_CALM (0x0b), |
| 124 | + |
| 125 | + /** |
| 126 | + * Negotiated TLS parameters not acceptable. |
| 127 | + * <p> |
| 128 | + * The underlying transport has properties that do not meet minimum security requirements. |
| 129 | + */ |
| 130 | + INADEQUATE_SECURITY (0x0c), |
| 131 | + |
| 132 | + /** |
| 133 | + * Use HTTP/1.1 for the request. |
| 134 | + * <p> |
| 135 | + * The endpoint requires that HTTP/1.1 be used instead of HTTP/2. |
| 136 | + */ |
| 137 | + HTTP_1_1_REQUIRED (0x0d); |
| 138 | + |
| 139 | + int code; |
| 140 | + |
| 141 | + H2Error(final int code) { |
| 142 | + this.code = code; |
| 143 | + } |
| 144 | + |
| 145 | + public int getCode() { |
| 146 | + return code; |
| 147 | + } |
| 148 | + |
| 149 | + private static final ConcurrentMap<Integer, H2Error> MAP_BY_CODE; |
| 150 | + static { |
| 151 | + MAP_BY_CODE = new ConcurrentHashMap<>(); |
| 152 | + for (final H2Error error: values()) { |
| 153 | + MAP_BY_CODE.putIfAbsent(error.code, error); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + public static H2Error getByCode(final int code) { |
| 158 | + return MAP_BY_CODE.get(code); |
| 159 | + } |
| 160 | + |
| 161 | +} |
0 commit comments