Class RequestValidator


  • class RequestValidator
    extends java.lang.Object
    The RequestValidator object is used to ensure requests for confirm to RFC 6455 section 4.2.1. The client opening handshake must consist of several parts, including a version of 13 referring to RFC 6455, a WebSocket key, and the required HTTP connection details. If any of these are missing the server is obliged to respond with a HTTP 400 response indicating a bad request.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Request request
      This is the request forming the client part of the handshake.
      private java.lang.String version
      This is the version referring to the required client version.
    • Constructor Summary

      Constructors 
      Constructor Description
      RequestValidator​(Request request)
      Constructor for the RequestValidator object.
      RequestValidator​(Request request, java.lang.String version)
      Constructor for the RequestValidator object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean isProtocol()
      This is used to determine if the request is a valid WebSocket handshake of the correct version.
      private boolean isUpgrade()
      Here we check to ensure that there is a HTTP connection header with the required upgrade token.
      boolean isValid()
      This is used to determine if the client handshake request had all the required headers as dictated by RFC 6455 section 4.2.1.
      • Methods inherited from class java.lang.Object

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

      • request

        private final Request request
        This is the request forming the client part of the handshake.
      • version

        private final java.lang.String version
        This is the version referring to the required client version.
    • Constructor Detail

      • RequestValidator

        public RequestValidator​(Request request)
        Constructor for the RequestValidator object. This is used to create a plain vanilla validator that uses version 13 as dictated by RFC 6455 section 4.2.1.
        Parameters:
        request - this is the handshake request from the client
      • RequestValidator

        public RequestValidator​(Request request,
                                java.lang.String version)
        Constructor for the RequestValidator object. This is used to create a plain vanilla validator that uses version 13 as dictated by RFC 6455 section 4.2.1.
        Parameters:
        request - this is the handshake request from the client
        version - a version other than 13 if desired
    • Method Detail

      • isValid

        public boolean isValid()
        This is used to determine if the client handshake request had all the required headers as dictated by RFC 6455 section 4.2.1. If the request does not contain any of these parts then this will return false, indicating a HTTP 400 response should be sent to the client.
        Returns:
        true if the request was a valid handshake
      • isProtocol

        private boolean isProtocol()
        This is used to determine if the request is a valid WebSocket handshake of the correct version. This also checks to see if the request contained the required handshake token.
        Returns:
        this returns true if the request is a valid handshake
      • isUpgrade

        private boolean isUpgrade()
        Here we check to ensure that there is a HTTP connection header with the required upgrade token. The upgrade token may be one of many, so all must be checked. Finally to ensure that the upgrade is for a WebSocket the upgrade header is checked.
        Returns:
        this returns true if the request is an upgrade