• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 Square, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.squareup.okhttp.internal.framed;
17 
18 // http://tools.ietf.org/html/draft-ietf-httpbis-http2-17#section-7
19 public enum ErrorCode {
20   /** Not an error! For SPDY stream resets, prefer null over NO_ERROR. */
21   NO_ERROR(0, -1, 0),
22 
23   PROTOCOL_ERROR(1, 1, 1),
24 
25   /** A subtype of PROTOCOL_ERROR used by SPDY. */
26   INVALID_STREAM(1, 2, -1),
27 
28   /** A subtype of PROTOCOL_ERROR used by SPDY. */
29   UNSUPPORTED_VERSION(1, 4, -1),
30 
31   /** A subtype of PROTOCOL_ERROR used by SPDY. */
32   STREAM_IN_USE(1, 8, -1),
33 
34   /** A subtype of PROTOCOL_ERROR used by SPDY. */
35   STREAM_ALREADY_CLOSED(1, 9, -1),
36 
37   INTERNAL_ERROR(2, 6, 2),
38 
39   FLOW_CONTROL_ERROR(3, 7, -1),
40 
41   STREAM_CLOSED(5, -1, -1),
42 
43   FRAME_TOO_LARGE(6, 11, -1),
44 
45   REFUSED_STREAM(7, 3, -1),
46 
47   CANCEL(8, 5, -1),
48 
49   COMPRESSION_ERROR(9, -1, -1),
50 
51   CONNECT_ERROR(10, -1, -1),
52 
53   ENHANCE_YOUR_CALM(11, -1, -1),
54 
55   INADEQUATE_SECURITY(12, -1, -1),
56 
57   HTTP_1_1_REQUIRED(13, -1, -1),
58 
59   INVALID_CREDENTIALS(-1, 10, -1);
60 
61   public final int httpCode;
62   public final int spdyRstCode;
63   public final int spdyGoAwayCode;
64 
ErrorCode(int httpCode, int spdyRstCode, int spdyGoAwayCode)65   private ErrorCode(int httpCode, int spdyRstCode, int spdyGoAwayCode) {
66     this.httpCode = httpCode;
67     this.spdyRstCode = spdyRstCode;
68     this.spdyGoAwayCode = spdyGoAwayCode;
69   }
70 
fromSpdy3Rst(int code)71   public static ErrorCode fromSpdy3Rst(int code) {
72     for (ErrorCode errorCode : ErrorCode.values()) {
73       if (errorCode.spdyRstCode == code) return errorCode;
74     }
75     return null;
76   }
77 
fromHttp2(int code)78   public static ErrorCode fromHttp2(int code) {
79     for (ErrorCode errorCode : ErrorCode.values()) {
80       if (errorCode.httpCode == code) return errorCode;
81     }
82     return null;
83   }
84 
fromSpdyGoAway(int code)85   public static ErrorCode fromSpdyGoAway(int code) {
86     for (ErrorCode errorCode : ErrorCode.values()) {
87       if (errorCode.spdyGoAwayCode == code) return errorCode;
88     }
89     return null;
90   }
91 }
92