diff --git a/src/main/java/org/java_websocket/framing/CloseFrame.java b/src/main/java/org/java_websocket/framing/CloseFrame.java index fd2ff71ad..8fbadfe1e 100644 --- a/src/main/java/org/java_websocket/framing/CloseFrame.java +++ b/src/main/java/org/java_websocket/framing/CloseFrame.java @@ -112,6 +112,31 @@ public class CloseFrame extends ControlFrame { * fulfilling the request. **/ public static final int UNEXPECTED_CONDITION = 1011; + /** + * 1012 indicates that the service is restarted. + * A client may reconnect, and if it choses to do, should reconnect using a randomized delay of 5 - 30s. + * See https://www.ietf.org/mail-archive/web/hybi/current/msg09670.html for more information. + * + * @since 1.3.8 + **/ + public static final int SERVICE_RESTART = 1012; + /** + * 1013 indicates that the service is experiencing overload. + * A client should only connect to a different IP (when there are multiple for the target) + * or reconnect to the same IP upon user action. + * See https://www.ietf.org/mail-archive/web/hybi/current/msg09670.html for more information. + * + * @since 1.3.8 + **/ + public static final int TRY_AGAIN_LATER = 1013; + /** + * 1014 indicates that the server was acting as a gateway or proxy and received an + * invalid response from the upstream server. This is similar to 502 HTTP Status Code + * See https://www.ietf.org/mail-archive/web/hybi/current/msg10748.html fore more information. + * + * @since 1.3.8 + **/ + public static final int BAD_GATEWAY = 1014; /** * 1015 is a reserved value and MUST NOT be set as a status code in a * Close control frame by an endpoint. It is designated for use in @@ -216,7 +241,7 @@ public void isValid() throws InvalidDataException { throw new InvalidDataException(PROTOCOL_ERROR, "A close frame must have a closecode if it has a reason"); } //Intentional check for code != CloseFrame.TLS_ERROR just to make sure even if the code earlier changes - if ((code > CloseFrame.UNEXPECTED_CONDITION && code < 3000 && code != CloseFrame.TLS_ERROR)) { + if ((code > CloseFrame.TLS_ERROR && code < 3000)) { throw new InvalidDataException(PROTOCOL_ERROR, "Trying to send an illegal close code!"); } if (code == CloseFrame.ABNORMAL_CLOSE || code == CloseFrame.TLS_ERROR || code == CloseFrame.NOCODE || code > 4999 || code < 1000 || code == 1004) { diff --git a/src/test/java/org/java_websocket/autobahn/AutobahnServerResults.java b/src/test/java/org/java_websocket/autobahn/AutobahnServerResults.java index b081014af..2d641fa9f 100644 --- a/src/test/java/org/java_websocket/autobahn/AutobahnServerResults.java +++ b/src/test/java/org/java_websocket/autobahn/AutobahnServerResults.java @@ -1970,15 +1970,7 @@ public void test7_9_5() { assertEquals( "OK", testResult.get( "behaviorClose" ) ); Assume.assumeTrue("Duration: " + testResult.getInt( "duration" ), testResult.getInt( "duration" ) < 10 ); } - - @Test - public void test7_9_6() { - JSONObject testResult = jsonObject.getJSONObject( "7.9.6" ); - assertEquals( "OK", testResult.get( "behavior" ) ); - assertEquals( "OK", testResult.get( "behaviorClose" ) ); - Assume.assumeTrue("Duration: " + testResult.getInt( "duration" ), testResult.getInt( "duration" ) < 10 ); - } - + @Test public void test7_9_7() { JSONObject testResult = jsonObject.getJSONObject( "7.9.7" ); diff --git a/src/test/java/org/java_websocket/framing/CloseFrameTest.java b/src/test/java/org/java_websocket/framing/CloseFrameTest.java index c926f76cf..24553bf81 100644 --- a/src/test/java/org/java_websocket/framing/CloseFrameTest.java +++ b/src/test/java/org/java_websocket/framing/CloseFrameTest.java @@ -167,6 +167,24 @@ public void testIsValid() { } catch (InvalidDataException e) { fail("InvalidDataException should not be thrown"); } + frame.setCode(CloseFrame.SERVICE_RESTART); + try { + frame.isValid(); + } catch (InvalidDataException e) { + fail("InvalidDataException should not be thrown"); + } + frame.setCode(CloseFrame.TRY_AGAIN_LATER); + try { + frame.isValid(); + } catch (InvalidDataException e) { + fail("InvalidDataException should not be thrown"); + } + frame.setCode(CloseFrame.BAD_GATEWAY); + try { + frame.isValid(); + } catch (InvalidDataException e) { + fail("InvalidDataException should not be thrown"); + } frame.setCode(CloseFrame.TLS_ERROR); try { frame.isValid();