Using NO_CODE instead of -1 for close frame with no status code declared
This commit is contained in:
parent
b6bf6899a9
commit
4f7c66ae81
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue