Skip to content

Commit 1204eae

Browse files
committed
3.4.5
1 parent ffda6eb commit 1204eae

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

dist/websocket-3.4.5.jar

-20 Bytes
Binary file not shown.

src/org/miktim/websocket/HttpHead.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static String join(Object[] array, char delimiter) {
3737
return sb.deleteCharAt(sb.length() - 1).toString();
3838
}
3939

40-
private final TreeMap<String, String> head = new TreeMap<String,String>(String.CASE_INSENSITIVE_ORDER);
40+
private final TreeMap<String, String> head = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
4141

4242
public HttpHead() {
4343
}
@@ -68,7 +68,9 @@ public String get(String key) {
6868
}
6969

7070
public HttpHead setValues(String key, String[] values) {
71-
if (values == null) return this;
71+
if (values == null) {
72+
return this;
73+
}
7274
return set(key, join(values, ','));
7375
}
7476

@@ -97,22 +99,23 @@ public List<String> nameList() {
9799
public Map<String, String> headMap() {
98100
return head;
99101
}
100-
101-
String readLine(InputStream is) throws IOException {
102+
103+
String readHeaderLine(InputStream is) throws IOException {
102104
byte[] bb = new byte[1024];
103105
int i = 0;
104106
int b = is.read();
105107
while (b != '\n' && b != -1) {
106108
bb[i++] = (byte) b;
107109
b = is.read();
108110
}
109-
return (new String(bb, 0, i)).replace("\r", "");
111+
if (b == '\n' && bb[i - 1] == '\r') {
112+
return new String(bb, 0, i - 1); // header line MUST ended CRLF
113+
}
114+
throw new ProtocolException();
110115
}
111-
116+
112117
public HttpHead read(InputStream is) throws IOException {
113-
// BufferedReader br = new BufferedReader(
114-
// new InputStreamReader(is));
115-
String line = readLine(is);
118+
String line = readHeaderLine(is);
116119
// if (line.startsWith("\u0016\u0003\u0003")) {
117120
// throw new javax.net.ssl.SSLHandshakeException("Plain socket");
118121
// }
@@ -124,7 +127,7 @@ public HttpHead read(InputStream is) throws IOException {
124127
set(START_LINE, line);
125128
String key = null;
126129
while (true) {
127-
line = readLine(is);
130+
line = readHeaderLine(is);
128131
if (line == null || line.isEmpty()) {
129132
break;
130133
}

src/org/miktim/websocket/WsReceiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ boolean controlFrame(int b1) throws IOException {
225225
conn.status.remotely = true;
226226
conn.socket.setSoTimeout(conn.wsp.handshakeSoTimeout);
227227
// send approval
228-
conn.sendControlFrame(OP_CLOSE, framePayload, framePayload.length); // extract status code and reason
228+
conn.sendControlFrame(OP_CLOSE,
229+
framePayload, framePayload.length);
230+
// extract status code and reason
229231
if (framePayload.length > 1) {
230232
conn.status.code = ((framePayload[0] & 0xFF) << 8)
231233
+ (framePayload[1] & 0xFF);

0 commit comments

Comments
 (0)