public class WebSocketRequest extends Object
A handshake request contains data like host, port, resource name. See RFC6455 §4.1.
A WebSocket request is embedded in an HTTP request,
therefore a WebSocketRequest
is associated with an HttpRequest
.
Constructor and Description |
---|
WebSocketRequest(String uri)
Create a WebSocketRequest from a WebSocket URI.
|
WebSocketRequest(boolean secure,
String hostPort,
String resourceName,
String origin,
String... subprotocols)
Create a WebSocketRequest.
|
WebSocketRequest(HttpRequest httpRequest)
Created a WebSocketRequest based on an HttpRequest.
|
Instance Methods | |
---|---|
InetAddress |
ip()
The IP address of the client.
|
String |
hostPort()
The host[:port] of the server.
|
String |
resourceName()
The resource name.
|
boolean |
secure()
Whether the connection is secure.
|
List<String> |
subprotocols()
The subprotocols.
|
String |
origin()
The origin.
|
HttpRequest |
httpRequest()
The HTTP request associated with this WebSocket handshake request.
|
public WebSocketRequest(String uri)
The created WebSocketRequest will have the same origin, and no subprotocols.
Example Usage:
new WebSocketRequest("ws://localhost:8080"); new WebSocketRequest("wss://example.com/chat");
public WebSocketRequest(boolean secure, String hostPort, String resourceName, String origin, String... subprotocols)
Example usage:
new WebSocketRequest(false, "localhost:8080", "/", null); new WebSocketRequest(true, "example.com", "/chat", "https://example.com");
public WebSocketRequest(HttpRequest httpRequest) throws IllegalArgumentException
The HttpRequest must form a valid WebSocket handshake request.
IllegalArgumentException
- if the http request is not a valid WebSocket handshake requestpublic InetAddress ip()
public String hostPort()
HttpRequest.host()
.
Example values: "localhost:8080", "example.com"
.
public String resourceName()
Example values: "/", "/chat"
.
public boolean secure()
public String origin()
Example values: null, "http://localhost:8080", "https://example.com"
.
public HttpRequest httpRequest()