Class RequestValidator
- java.lang.Object
-
- org.simpleframework.http.socket.service.RequestValidator
-
class RequestValidator extends java.lang.Object
TheRequestValidator
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.
-
-
Constructor Summary
Constructors Constructor Description RequestValidator(Request request)
Constructor for theRequestValidator
object.RequestValidator(Request request, java.lang.String version)
Constructor for theRequestValidator
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.
-
-
-
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 theRequestValidator
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 theRequestValidator
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 clientversion
- 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
-
-