Skip to content

Commit 461d6c5

Browse files
committed
Bug: 459142 - WebSocket support for the Java client
Fixing Bug where incorrect case caused failed header upgrade Changed Request headers to use hardcoded \r\n instead of relying on the host machine. Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent d24aaff commit 461d6c5

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

  • org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/websocket

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/websocket/WebSocketHandshake.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class WebSocketHandshake {
3838
private static final String HTTP_HEADER_UPGRADE = "Upgrade";
3939
private static final String HTTP_HEADER_UPGRADE_WEBSOCKET = "websocket";
4040
private static final String EMPTY = "";
41+
private static final String LINE_SEPARATOR = "\r\n";
4142

4243
InputStream input;
4344
OutputStream output;
@@ -73,14 +74,14 @@ public void execute() throws IOException {
7374
*/
7475
private void sendHandshakeRequest(String key) throws IOException{
7576
PrintWriter pw = new PrintWriter(output);
76-
pw.println("GET /mqtt HTTP/1.1");
77-
pw.println("Host: " + host + ":" + port);
78-
pw.println("Upgrade: websocket");
79-
pw.println("Connection: Upgrade");
80-
pw.println("Sec-WebSocket-Key: " + key);
81-
pw.println("Sec-WebSocket-Protocol: mqtt");
82-
pw.println("Sec-WebSocket-Version: 13");
83-
pw.println("");
77+
pw.print("GET /mqtt HTTP/1.1" + LINE_SEPARATOR);
78+
pw.print("Host: " + host + ":" + port + LINE_SEPARATOR);
79+
pw.print("Upgrade: websocket" + LINE_SEPARATOR);
80+
pw.print("Connection: Upgrade" + LINE_SEPARATOR);
81+
pw.print("Sec-WebSocket-Key: " + key + LINE_SEPARATOR);
82+
pw.print("Sec-WebSocket-Protocol: mqtt" + LINE_SEPARATOR);
83+
pw.print("Sec-WebSocket-Version: 13" + LINE_SEPARATOR);
84+
pw.print(LINE_SEPARATOR);
8485
pw.flush();
8586
}
8687

@@ -99,7 +100,7 @@ private void receiveHandshakeResponse(String key) throws IOException {
99100
}
100101
Map headerMap = getHeaders(responseLines);
101102
String upgradeHeader = (String) headerMap.get(HTTP_HEADER_UPGRADE);
102-
if(!upgradeHeader.contains(HTTP_HEADER_UPGRADE_WEBSOCKET)){
103+
if(!upgradeHeader.toLowerCase().contains(HTTP_HEADER_UPGRADE_WEBSOCKET.toLowerCase())){
103104
throw new IOException("WebSocket Response header: Incorrect upgrade.");
104105
}
105106

0 commit comments

Comments
 (0)