Package org.microproxy.http
Record Class WebSocketMessage
java.lang.Object
java.lang.Record
org.microproxy.http.WebSocketMessage
- Record Components:
type- whether the message is text or binarypayload- the application data (UTF-8 for a text message)fromClient- whether the message travels from the client towards the server
public record WebSocketMessage(WebSocketMessage.Type type, byte[] payload, boolean fromClient)
extends Record
A whole WebSocket message (RFC 6455 section 5.4): the payloads of a text or binary frame and its
continuation frames, joined, and inflated when the connection uses permessage-deflate (RFC
7692). Messages relayed after an upgrade are shown to
HttpFilters.filterWebSocketMessage(WebSocketMessage, boolean), which may return
one built with text(String, boolean), binary(byte[], boolean), withText(String) and the like to send instead.
Messages are immutable: the payload is copied in and out.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe kind of data a message carries (its first frame's opcode). -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketMessage(WebSocketMessage.Type type, byte[] payload, boolean fromClient) A message, with a copy ofpayload. -
Method Summary
Modifier and TypeMethodDescriptionstatic WebSocketMessagebinary(byte[] data, boolean fromClient) A binary message.booleanWhetherotherhas the same type, direction and payload.booleanReturns the value of thefromClientrecord component.inthashCode()Returns a hash code value for this object.booleanisBinary()Checks the message type.booleanisText()Checks the message type.intlength()Returns the payload length.byte[]payload()Returns a copy of the application data.text()The payload decoded as UTF-8, with malformed input replaced (meaningful for text messages).static WebSocketMessageA text message.The payload decoded as UTF-8, ornullif it is not valid UTF-8.toString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.withFromClient(boolean fromClient) This message travelling the other way, or the same way: a hook that returns it withfromClientchanged sends it back to where the original came from.withPayload(byte[] data) This message with another payload, keeping its type and direction.This message with another payload, encoded as UTF-8, keeping its type and direction.withType(WebSocketMessage.Type newType) This message as another type, keeping its payload and direction.
-
Constructor Details
-
WebSocketMessage
A message, with a copy ofpayload.- Parameters:
type- whether the message is text or binarypayload- the application data, copiedfromClient- whether the message travels from the client towards the server
-
-
Method Details
-
text
A text message.- Parameters:
text- the text, encoded as UTF-8fromClient- whether the message travels towards the server- Returns:
- a text message
-
binary
A binary message.- Parameters:
data- the payload, copiedfromClient- whether the message travels towards the server- Returns:
- a binary message
-
payload
public byte[] payload()Returns a copy of the application data.- Returns:
- the payload bytes
-
length
public int length()Returns the payload length.- Returns:
- the number of payload bytes
-
isText
public boolean isText()Checks the message type.- Returns:
- whether this is a text message
-
isBinary
public boolean isBinary()Checks the message type.- Returns:
- whether this is a binary message
-
text
The payload decoded as UTF-8, with malformed input replaced (meaningful for text messages).- Returns:
- the payload as text
-
textOrNull
The payload decoded as UTF-8, ornullif it is not valid UTF-8.- Returns:
- the payload as text, or null
-
withPayload
This message with another payload, keeping its type and direction.- Parameters:
data- the new payload, copied- Returns:
- a new message
-
withText
This message with another payload, encoded as UTF-8, keeping its type and direction.- Parameters:
text- the new payload text- Returns:
- a new message
-
withType
This message as another type, keeping its payload and direction.- Parameters:
newType- the new type- Returns:
- a new message
-
withFromClient
This message travelling the other way, or the same way: a hook that returns it withfromClientchanged sends it back to where the original came from.- Parameters:
fromClient- whether the new message travels from the client towards the server- Returns:
- a new message
-
equals
Whetherotherhas the same type, direction and payload. -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
type
Returns the value of thetyperecord component.- Returns:
- the value of the
typerecord component
-
fromClient
public boolean fromClient()Returns the value of thefromClientrecord component.- Returns:
- the value of the
fromClientrecord component
-