Home | History | Annotate | Download | only in spdy
      1 package com.squareup.okhttp.internal.spdy;
      2 
      3 // TODO: revisit for http/2 draft 9
      4 // http://tools.ietf.org/html/draft-ietf-httpbis-http2-09#section-7
      5 public enum ErrorCode {
      6   /** Not an error! For SPDY stream resets, prefer null over NO_ERROR. */
      7   NO_ERROR(0, -1, 0),
      8 
      9   PROTOCOL_ERROR(1, 1, 1),
     10 
     11   /** A subtype of PROTOCOL_ERROR used by SPDY. */
     12   INVALID_STREAM(1, 2, -1),
     13 
     14   /** A subtype of PROTOCOL_ERROR used by SPDY. */
     15   UNSUPPORTED_VERSION(1, 4, -1),
     16 
     17   /** A subtype of PROTOCOL_ERROR used by SPDY. */
     18   STREAM_IN_USE(1, 8, -1),
     19 
     20   /** A subtype of PROTOCOL_ERROR used by SPDY. */
     21   STREAM_ALREADY_CLOSED(1, 9, -1),
     22 
     23   INTERNAL_ERROR(2, 6, 2),
     24 
     25   FLOW_CONTROL_ERROR(3, 7, -1),
     26 
     27   STREAM_CLOSED(5, -1, -1),
     28 
     29   FRAME_TOO_LARGE(6, 11, -1),
     30 
     31   REFUSED_STREAM(7, 3, -1),
     32 
     33   CANCEL(8, 5, -1),
     34 
     35   COMPRESSION_ERROR(9, -1, -1),
     36 
     37   INVALID_CREDENTIALS(-1, 10, -1);
     38 
     39   public final int httpCode;
     40   public final int spdyRstCode;
     41   public final int spdyGoAwayCode;
     42 
     43   private ErrorCode(int httpCode, int spdyRstCode, int spdyGoAwayCode) {
     44     this.httpCode = httpCode;
     45     this.spdyRstCode = spdyRstCode;
     46     this.spdyGoAwayCode = spdyGoAwayCode;
     47   }
     48 
     49   public static ErrorCode fromSpdy3Rst(int code) {
     50     for (ErrorCode errorCode : ErrorCode.values()) {
     51       if (errorCode.spdyRstCode == code) return errorCode;
     52     }
     53     return null;
     54   }
     55 
     56   public static ErrorCode fromHttp2(int code) {
     57     for (ErrorCode errorCode : ErrorCode.values()) {
     58       if (errorCode.httpCode == code) return errorCode;
     59     }
     60     return null;
     61   }
     62 
     63   public static ErrorCode fromSpdyGoAway(int code) {
     64     for (ErrorCode errorCode : ErrorCode.values()) {
     65       if (errorCode.spdyGoAwayCode == code) return errorCode;
     66     }
     67     return null;
     68   }
     69 }
     70