Skip to content

Commit 8c9e785

Browse files
committed
Merge branch 'master' of https://github.com/DanielYWoo/Java-WebSocket into fix86
2 parents 86b5913 + 1e34c14 commit 8c9e785

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/org/java_websocket/WebSocketClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.nio.channels.SocketChannel;
1212
import java.nio.channels.UnresolvedAddressException;
1313
import java.util.Iterator;
14+
import java.util.Map;
1415
import java.util.Set;
1516
import java.util.concurrent.locks.Lock;
1617
import java.util.concurrent.locks.ReentrantLock;
@@ -58,6 +59,8 @@ public abstract class WebSocketClient extends WebSocketAdapter implements Runnab
5859

5960
private final Lock closelock = new ReentrantLock();
6061

62+
private Map<String, String> headers;
63+
6164
public WebSocketClient( URI serverURI ) {
6265
this( serverURI, new Draft_10() );
6366
}
@@ -68,6 +71,10 @@ public WebSocketClient( URI serverURI ) {
6871
* must call <var>connect</var> first to initiate the socket connection.
6972
*/
7073
public WebSocketClient( URI serverUri , Draft draft ) {
74+
this(serverUri, draft, null);
75+
}
76+
77+
public WebSocketClient( URI serverUri , Draft draft, Map<String, String> headers) {
7178
if( serverUri == null ) {
7279
throw new IllegalArgumentException();
7380
}
@@ -76,6 +83,7 @@ public WebSocketClient( URI serverUri , Draft draft ) {
7683
}
7784
this.uri = serverUri;
7885
this.draft = draft;
86+
this.headers = headers;
7987
}
8088

8189
/**
@@ -279,6 +287,11 @@ private void sendHandshake() throws IOException , InvalidHandshakeException , In
279287
HandshakeImpl1Client handshake = new HandshakeImpl1Client();
280288
handshake.setResourceDescriptor( path );
281289
handshake.put( "Host", host );
290+
if (headers != null) {
291+
for (Map.Entry<String, String> kv : headers.entrySet()) {
292+
handshake.put(kv.getKey(), kv.getValue());
293+
}
294+
}
282295
conn.startHandshake( handshake );
283296
}
284297

0 commit comments

Comments
 (0)