Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for ws.closeWithReason() Cleaned my messy Signed-off-by: francesco <francescoguard@gmail.com>
- Loading branch information
1 parent
c75d7cc
commit dc1ab18
Showing
9 changed files
with
145 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/io/vertx/core/http/impl/ws/WebSocketCloseFrameCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.vertx.core.http.impl.ws; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
/** | ||
* @author Francesco Guardiani @slinkydeveloper | ||
*/ | ||
public enum WebSocketCloseFrameCode { | ||
|
||
NORMAL_CLOSE((short)1000, "Connection Closed"); | ||
|
||
private short statusCode; | ||
private String reason; | ||
|
||
WebSocketCloseFrameCode(short statusCode, String reason) { | ||
this.statusCode = statusCode; | ||
this.reason = reason; | ||
} | ||
|
||
public ByteBuf byteBuf() { | ||
return generateByteBuffer(this.statusCode, this.reason); | ||
} | ||
|
||
public static ByteBuf generateByteBuffer(short statusCode, String reason) { | ||
if (reason != null) | ||
return Unpooled.copiedBuffer( | ||
Unpooled.copyShort(statusCode), // First two bytes are reserved for status code | ||
Unpooled.copiedBuffer(reason, Charset.forName("UTF-8")) | ||
); | ||
else | ||
return Unpooled.copyShort(statusCode); | ||
} | ||
|
||
} |
18 changes: 0 additions & 18 deletions
18
src/main/java/io/vertx/core/http/impl/ws/WebSocketCloseFrameCodes.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters