Class HandshakeReader


  • class HandshakeReader
    extends java.lang.Object
    Reader for a WebSocket opening handshake response.
    Since:
    1.19
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int getContentLength​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
      Get the value of "Content-Length" header.
      private void parseHttpHeader​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, java.lang.String header)  
      private byte[] readBody​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, WebSocketInputStream input)
      Read the response body
      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> readHandshake​(WebSocketInputStream input, java.lang.String key)  
      private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> readHttpHeaders​(WebSocketInputStream input)  
      private StatusLine readStatusLine​(WebSocketInputStream input)
      Read a status line from an HTTP server.
      private void validateAccept​(StatusLine statusLine, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, java.lang.String key)
      Validate the value of Sec-WebSocket-Accept header.
      private void validateConnection​(StatusLine statusLine, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
      Validate the value of Connection header.
      private void validateExtensionCombination​(StatusLine statusLine, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, java.util.List<WebSocketExtension> extensions)  
      private void validateExtensions​(StatusLine statusLine, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
      Validate the value of Sec-WebSocket-Extensions header.
      private void validateProtocol​(StatusLine statusLine, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
      Validate the value of Sec-WebSocket-Protocol header.
      private void validateStatusLine​(StatusLine statusLine, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, WebSocketInputStream input)
      Validate the status line.
      private void validateUpgrade​(StatusLine statusLine, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
      Validate the value of Upgrade header.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HandshakeReader

        public HandshakeReader​(WebSocket websocket)
    • Method Detail

      • parseHttpHeader

        private void parseHttpHeader​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                                     java.lang.String header)
      • readBody

        private byte[] readBody​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                                WebSocketInputStream input)
        Read the response body
      • getContentLength

        private int getContentLength​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
        Get the value of "Content-Length" header.
      • validateUpgrade

        private void validateUpgrade​(StatusLine statusLine,
                                     java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
                              throws WebSocketException
        Validate the value of Upgrade header.

        From RFC 6455, p19.

        If the response lacks an Upgrade header field or the Upgrade 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,
                                        java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
                                 throws WebSocketException
        Validate the value of Connection header.

        From RFC 6455, p19.

        If the response lacks a Connection header field or the Connection 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,
                                    java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                                    java.lang.String key)
                             throws WebSocketException
        Validate the value of Sec-WebSocket-Accept header.

        From RFC 6455, p19.

        If the response lacks a Sec-WebSocket-Accept header field or the Sec-WebSocket-Accept contains a value other than the base64-encoded SHA-1 of the concatenation of the Sec-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,
                                        java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
                                 throws WebSocketException
        Validate the value of Sec-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
      • validateProtocol

        private void validateProtocol​(StatusLine statusLine,
                                      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
                               throws WebSocketException
        Validate the value of Sec-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