Class HandshakeReader
- Since:
- 1.19
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate int
getContentLength
(Map<String, List<String>> headers) Get the value of "Content-Length" header.private void
private byte[]
Read the response bodyreadHandshake
(WebSocketInputStream input, String key) private StatusLine
Read a status line from an HTTP server.private void
validateAccept
(StatusLine statusLine, Map<String, List<String>> headers, String key) Validate the value ofSec-WebSocket-Accept
header.private void
validateConnection
(StatusLine statusLine, Map<String, List<String>> headers) Validate the value ofConnection
header.private void
validateExtensionCombination
(StatusLine statusLine, Map<String, List<String>> headers, List<WebSocketExtension> extensions) private void
validateExtensions
(StatusLine statusLine, Map<String, List<String>> headers) Validate the value ofSec-WebSocket-Extensions
header.private void
validateProtocol
(StatusLine statusLine, Map<String, List<String>> headers) Validate the value ofSec-WebSocket-Protocol
header.private void
validateStatusLine
(StatusLine statusLine, Map<String, List<String>> headers, WebSocketInputStream input) Validate the status line.private void
validateUpgrade
(StatusLine statusLine, Map<String, List<String>> headers) Validate the value ofUpgrade
header.
-
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 ofUpgrade
header.From RFC 6455, p19.
If the response lacks an
Upgrade
header field or theUpgrade
header 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 ofConnection
header.From RFC 6455, p19.
If the response lacks a
Connection
header field or theConnection
header 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-Accept
header.From RFC 6455, p19.
If the response lacks a
Sec-WebSocket-Accept
header field or theSec-WebSocket-Accept
contains 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-Extensions
header.From RFC 6455, p19.
If the response includes a
Sec-WebSocket-Extensions
header 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-Protocol
header.From RFC 6455, p20.
If the response includes a
Sec-WebSocket-Protocol
header 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
-