Using NO_CODE instead of -1 for close frame with no status code declared

This commit is contained in:
Joakim Erdfelt 2012-10-22 11:37:15 -07:00
parent b6bf6899a9
commit 4f7c66ae81
1 changed files with 15 additions and 13 deletions

View File

@ -38,12 +38,12 @@ public class CloseInfo
public CloseInfo() public CloseInfo()
{ {
this(-1,null); this(StatusCode.NO_CODE,null);
} }
public CloseInfo(ByteBuffer payload, boolean validate) public CloseInfo(ByteBuffer payload, boolean validate)
{ {
this.statusCode = -1; this.statusCode = StatusCode.NO_CODE;
this.reason = null; this.reason = null;
if ((payload == null) || (payload.remaining() == 0)) if ((payload == null) || (payload.remaining() == 0))
@ -130,19 +130,21 @@ public class CloseInfo
public ByteBuffer asByteBuffer() public ByteBuffer asByteBuffer()
{ {
if (statusCode != (-1)) if ((statusCode == StatusCode.NO_CLOSE) || (statusCode == StatusCode.NO_CODE) || (statusCode == (-1)))
{ {
ByteBuffer buf = ByteBuffer.allocate(WebSocketFrame.MAX_CONTROL_PAYLOAD); // codes that are not allowed to be used in endpoint.
buf.putChar((char)statusCode); return null;
if (StringUtil.isNotBlank(reason))
{
byte utf[] = StringUtil.getUtf8Bytes(reason);
buf.put(utf,0,utf.length);
}
BufferUtil.flipToFlush(buf,0);
return buf;
} }
return null;
ByteBuffer buf = ByteBuffer.allocate(WebSocketFrame.MAX_CONTROL_PAYLOAD);
buf.putChar((char)statusCode);
if (StringUtil.isNotBlank(reason))
{
byte utf[] = StringUtil.getUtf8Bytes(reason);
buf.put(utf,0,utf.length);
}
BufferUtil.flipToFlush(buf,0);
return buf;
} }
public WebSocketFrame asFrame() public WebSocketFrame asFrame()