Class RequestValidator
java.lang.Object
org.simpleframework.http.socket.service.RequestValidator
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 -
Constructor Summary
ConstructorsConstructorDescriptionRequestValidator
(Request request) Constructor for theRequestValidator
object.RequestValidator
(Request request, String version) Constructor for theRequestValidator
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
This is used to determine if the request is a valid WebSocket handshake of the correct version.private boolean
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 Details
-
request
This is the request forming the client part of the handshake. -
version
This is the version referring to the required client version.
-
-
Constructor Details
-
RequestValidator
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
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 Details
-
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
-