use of org.java_websocket.handshake.HandshakeImpl1Client in project quorrabot by GloriousEggroll.
the class WebSocketClient method sendHandshake.
private void sendHandshake() throws InvalidHandshakeException {
String path;
String part1 = uri.getPath();
String part2 = uri.getQuery();
if (part1 == null || part1.length() == 0) {
path = "/";
} else {
path = part1;
}
if (part2 != null) {
path += "?" + part2;
}
int port = getPort();
String host = uri.getHost() + (port != WebSocket.DEFAULT_PORT ? ":" + port : "");
HandshakeImpl1Client handshake = new HandshakeImpl1Client();
handshake.setResourceDescriptor(path);
handshake.put("Host", host);
if (headers != null) {
for (Map.Entry<String, String> kv : headers.entrySet()) {
handshake.put(kv.getKey(), kv.getValue());
}
}
engine.startHandshake(handshake);
}
use of org.java_websocket.handshake.HandshakeImpl1Client in project quorrabot by GloriousEggroll.
the class Draft method translateHandshakeHttp.
public static HandshakeBuilder translateHandshakeHttp(ByteBuffer buf, Role role) throws InvalidHandshakeException, IncompleteHandshakeException {
HandshakeBuilder handshake;
String line = readStringLine(buf);
if (line == null) {
throw new IncompleteHandshakeException(buf.capacity() + 128);
}
// eg. HTTP/1.1 101 Switching the Protocols
String[] firstLineTokens = line.split(" ", 3);
if (firstLineTokens.length != 3) {
throw new InvalidHandshakeException();
}
if (role == Role.CLIENT) {
// translating/parsing the response from the SERVER
handshake = new HandshakeImpl1Server();
ServerHandshakeBuilder serverhandshake = (ServerHandshakeBuilder) handshake;
serverhandshake.setHttpStatus(Short.parseShort(firstLineTokens[1]));
serverhandshake.setHttpStatusMessage(firstLineTokens[2]);
} else {
// translating/parsing the request from the CLIENT
ClientHandshakeBuilder clienthandshake = new HandshakeImpl1Client();
clienthandshake.setResourceDescriptor(firstLineTokens[1]);
handshake = clienthandshake;
}
line = readStringLine(buf);
while (line != null && line.length() > 0) {
String[] pair = line.split(":", 2);
if (pair.length != 2) {
throw new InvalidHandshakeException("not an http header");
}
handshake.put(pair[0], pair[1].replaceFirst("^ +", ""));
line = readStringLine(buf);
}
if (line == null) {
throw new IncompleteHandshakeException();
}
return handshake;
}
Aggregations