Class HandshakeReader
- Since:
- 1.19
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate intgetContentLength(Map<String, List<String>> headers) Get the value of "Content-Length" header.private voidprivate byte[]Read the response bodyreadHandshake(WebSocketInputStream input, String key) private StatusLineRead a status line from an HTTP server.private voidvalidateAccept(StatusLine statusLine, Map<String, List<String>> headers, String key) Validate the value ofSec-WebSocket-Acceptheader.private voidvalidateConnection(StatusLine statusLine, Map<String, List<String>> headers) Validate the value ofConnectionheader.private voidvalidateExtensionCombination(StatusLine statusLine, Map<String, List<String>> headers, List<WebSocketExtension> extensions) private voidvalidateExtensions(StatusLine statusLine, Map<String, List<String>> headers) Validate the value ofSec-WebSocket-Extensionsheader.private voidvalidateProtocol(StatusLine statusLine, Map<String, List<String>> headers) Validate the value ofSec-WebSocket-Protocolheader.private voidvalidateStatusLine(StatusLine statusLine, Map<String, List<String>> headers, WebSocketInputStream input) Validate the status line.private voidvalidateUpgrade(StatusLine statusLine, Map<String, List<String>> headers) Validate the value ofUpgradeheader.
-
Field Details
-
ACCEPT_MAGIC
- See Also:
-
mWebSocket
-
-
Constructor Details
-
HandshakeReader
-
-
Method Details
-
readHandshake
public Map<String,List<String>> readHandshake(WebSocketInputStream input, String key) throws WebSocketException - Throws:
WebSocketException
-
readStatusLine
Read a status line from an HTTP server.- Throws:
WebSocketException
-
readHttpHeaders
private Map<String,List<String>> readHttpHeaders(WebSocketInputStream input) throws WebSocketException - Throws:
WebSocketException
-
parseHttpHeader
-
validateStatusLine
private void validateStatusLine(StatusLine statusLine, Map<String, List<String>> headers, WebSocketInputStream input) throws WebSocketExceptionValidate the status line."101 Switching Protocols"is expected.- Throws:
WebSocketException
-
readBody
Read the response body -
getContentLength
Get the value of "Content-Length" header. -
validateUpgrade
private void validateUpgrade(StatusLine statusLine, Map<String, List<String>> headers) throws WebSocketExceptionValidate the value ofUpgradeheader.From RFC 6455, p19.
If the response lacks an
Upgradeheader field or theUpgradeheader field contains a value that is not an ASCII case-insensitive match for the value "websocket", the client MUST Fail the WebSocket Connection.- Throws:
WebSocketException
-
validateConnection
private void validateConnection(StatusLine statusLine, Map<String, List<String>> headers) throws WebSocketExceptionValidate the value ofConnectionheader.From RFC 6455, p19.
If the response lacks a
Connectionheader field or theConnectionheader field doesn't contain a token that is an ASCII case-insensitive match for the value "Upgrade", the client MUST Fail the WebSocket Connection.- Throws:
WebSocketException
-
validateAccept
private void validateAccept(StatusLine statusLine, Map<String, List<String>> headers, String key) throws WebSocketExceptionValidate the value ofSec-WebSocket-Acceptheader.From RFC 6455, p19.
If the response lacks a
Sec-WebSocket-Acceptheader field or theSec-WebSocket-Acceptcontains a value other than the base64-encoded SHA-1 of the concatenation of theSec-WebSocket-Key(as a string, not base64-decoded) with the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" but ignoring any leading and trailing whitespace, the client MUST Fail the WebSocket Connection.- Throws:
WebSocketException
-
validateExtensions
private void validateExtensions(StatusLine statusLine, Map<String, List<String>> headers) throws WebSocketExceptionValidate the value ofSec-WebSocket-Extensionsheader.From RFC 6455, p19.
If the response includes a
Sec-WebSocket-Extensionsheader field and this header field indicates the use of an extension that was not present in the client's handshake (the server has indicated an extension not requested by the client), the client MUST Fail the WebSocket Connection.- Throws:
WebSocketException
-
validateExtensionCombination
private void validateExtensionCombination(StatusLine statusLine, Map<String, List<String>> headers, List<WebSocketExtension> extensions) throws WebSocketException- Throws:
WebSocketException
-
validateProtocol
private void validateProtocol(StatusLine statusLine, Map<String, List<String>> headers) throws WebSocketExceptionValidate the value ofSec-WebSocket-Protocolheader.From RFC 6455, p20.
If the response includes a
Sec-WebSocket-Protocolheader field and this header field indicates the use of a subprotocol that was not present in the client's handshake (the server has indicated a subprotocol not requested by the client), the client MUST Fail the WebSocket Connection.- Throws:
WebSocketException
-