Skip to content

Commit c03890d

Browse files
authored
Merge pull request TooTallNate#651 from marci4/master
Support for close code 1012-1014
2 parents f259695 + 45390ea commit c03890d

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/main/java/org/java_websocket/framing/CloseFrame.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ public class CloseFrame extends ControlFrame {
112112
* fulfilling the request.
113113
**/
114114
public static final int UNEXPECTED_CONDITION = 1011;
115+
/**
116+
* 1012 indicates that the service is restarted.
117+
* A client may reconnect, and if it choses to do, should reconnect using a randomized delay of 5 - 30s.
118+
* See https://www.ietf.org/mail-archive/web/hybi/current/msg09670.html for more information.
119+
*
120+
* @since 1.3.8
121+
**/
122+
public static final int SERVICE_RESTART = 1012;
123+
/**
124+
* 1013 indicates that the service is experiencing overload.
125+
* A client should only connect to a different IP (when there are multiple for the target)
126+
* or reconnect to the same IP upon user action.
127+
* See https://www.ietf.org/mail-archive/web/hybi/current/msg09670.html for more information.
128+
*
129+
* @since 1.3.8
130+
**/
131+
public static final int TRY_AGAIN_LATER = 1013;
132+
/**
133+
* 1014 indicates that the server was acting as a gateway or proxy and received an
134+
* invalid response from the upstream server. This is similar to 502 HTTP Status Code
135+
* See https://www.ietf.org/mail-archive/web/hybi/current/msg10748.html fore more information.
136+
*
137+
* @since 1.3.8
138+
**/
139+
public static final int BAD_GATEWAY = 1014;
115140
/**
116141
* 1015 is a reserved value and MUST NOT be set as a status code in a
117142
* Close control frame by an endpoint. It is designated for use in
@@ -216,7 +241,7 @@ public void isValid() throws InvalidDataException {
216241
throw new InvalidDataException(PROTOCOL_ERROR, "A close frame must have a closecode if it has a reason");
217242
}
218243
//Intentional check for code != CloseFrame.TLS_ERROR just to make sure even if the code earlier changes
219-
if ((code > CloseFrame.UNEXPECTED_CONDITION && code < 3000 && code != CloseFrame.TLS_ERROR)) {
244+
if ((code > CloseFrame.TLS_ERROR && code < 3000)) {
220245
throw new InvalidDataException(PROTOCOL_ERROR, "Trying to send an illegal close code!");
221246
}
222247
if (code == CloseFrame.ABNORMAL_CLOSE || code == CloseFrame.TLS_ERROR || code == CloseFrame.NOCODE || code > 4999 || code < 1000 || code == 1004) {

src/test/java/org/java_websocket/autobahn/AutobahnServerResults.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,15 +1970,7 @@ public void test7_9_5() {
19701970
assertEquals( "OK", testResult.get( "behaviorClose" ) );
19711971
Assume.assumeTrue("Duration: " + testResult.getInt( "duration" ), testResult.getInt( "duration" ) < 10 );
19721972
}
1973-
1974-
@Test
1975-
public void test7_9_6() {
1976-
JSONObject testResult = jsonObject.getJSONObject( "7.9.6" );
1977-
assertEquals( "OK", testResult.get( "behavior" ) );
1978-
assertEquals( "OK", testResult.get( "behaviorClose" ) );
1979-
Assume.assumeTrue("Duration: " + testResult.getInt( "duration" ), testResult.getInt( "duration" ) < 10 );
1980-
}
1981-
1973+
19821974
@Test
19831975
public void test7_9_7() {
19841976
JSONObject testResult = jsonObject.getJSONObject( "7.9.7" );

src/test/java/org/java_websocket/framing/CloseFrameTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ public void testIsValid() {
167167
} catch (InvalidDataException e) {
168168
fail("InvalidDataException should not be thrown");
169169
}
170+
frame.setCode(CloseFrame.SERVICE_RESTART);
171+
try {
172+
frame.isValid();
173+
} catch (InvalidDataException e) {
174+
fail("InvalidDataException should not be thrown");
175+
}
176+
frame.setCode(CloseFrame.TRY_AGAIN_LATER);
177+
try {
178+
frame.isValid();
179+
} catch (InvalidDataException e) {
180+
fail("InvalidDataException should not be thrown");
181+
}
182+
frame.setCode(CloseFrame.BAD_GATEWAY);
183+
try {
184+
frame.isValid();
185+
} catch (InvalidDataException e) {
186+
fail("InvalidDataException should not be thrown");
187+
}
170188
frame.setCode(CloseFrame.TLS_ERROR);
171189
try {
172190
frame.isValid();

0 commit comments

Comments
 (0)