oberstet/AutobahnAndroid — Issue #1: Superflorous newline breaks communication with CherryPy/ws4py
Author: ysangkok
Created: 2011-11-26 23:27:37+00:00
State: open

Hex dump of TCP stream send by AutobahnAndroid:
00000000 47 45 54 20 2f 77 73 2f 65 63 68 6f 2f 20 48 54 GET /ws/ echo/ HT
00000010 54 50 2f 31 2e 31 0d 0a 48 6f 73 74 3a 20 31 39 TP/1.1.. Host: 19
00000020 32 2e 31 36 38 2e 30 2e 37 3a 39 38 38 34 0d 0a 2.168.0. 7:9884..
00000030 55 70 67 72 61 64 65 3a 20 57 65 62 53 6f 63 6b Upgrade: WebSock
00000040 65 74 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 et..Conn ection:
00000050 55 70 67 72 61 64 65 0d 0a 53 65 63 2d 57 65 62 Upgrade. .Sec-Web
00000060 53 6f 63 6b 65 74 2d 4b 65 79 3a 20 33 6a 4b 4d Socket-K ey: 3jKM
00000070 4d 56 32 66 47 31 57 78 57 54 65 45 73 53 6f 54 MV2fG1Wx WTeEsSoT
00000080 57 67 3d 3d 0a 0d 0a 53 65 63 2d 57 65 62 53 6f Wg==...S ec-WebSo
00000090 63 6b 65 74 2d 56 65 72 73 69 6f 6e 3a 20 31 33 cket-Ver sion: 13
000000A0 0d 0a 0d 0a ....

As you see, at 00000085 we have a superflorous newline (0x0a).

The code that writes this stuff is in AutobahnWriter.java.

mBuffer.write("GET " + path + " HTTP/1.1");
mBuffer.crlf();
mBuffer.write("Host: " + message.mHost);
mBuffer.crlf();
mBuffer.write("Upgrade: WebSocket");
mBuffer.crlf();
mBuffer.write("Connection: Upgrade");
mBuffer.crlf();
mBuffer.write("Sec-WebSocket-Key: " + newHandshakeKey());
mBuffer.crlf();
if (message.mOrigin != null && !message.mOrigin.equals("")) {
mBuffer.write("Origin: " + message.mOrigin);
mBuffer.crlf();
}
mBuffer.write("Sec-WebSocket-Version: 13");
mBuffer.crlf();
mBuffer.crlf();

Apparently message.mOrigin has a extra newline at the end.

Suggested fix: Do not append the newline in the first place, or trim the origin.