Skip to content

Commit 954ab8b

Browse files
committed
add customized headers support
1 parent 9e6882d commit 954ab8b

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/org/java_websocket/WebSocketClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public WebSocketClient( URI serverURI ) {
6868
* must call <var>connect</var> first to initiate the socket connection.
6969
*/
7070
public WebSocketClient( URI serverUri , Draft draft ) {
71+
this(serverUri, draft, null);
72+
}
73+
74+
public WebSocketClient( URI serverUri , Draft draft, Map<String, String> headers) {
7175
if( serverUri == null ) {
7276
throw new IllegalArgumentException();
7377
}
@@ -76,6 +80,7 @@ public WebSocketClient( URI serverUri , Draft draft ) {
7680
}
7781
this.uri = serverUri;
7882
this.draft = draft;
83+
this.headers = headers;
7984
}
8085

8186
/**
@@ -279,6 +284,11 @@ private void sendHandshake() throws IOException , InvalidHandshakeException , In
279284
HandshakeImpl1Client handshake = new HandshakeImpl1Client();
280285
handshake.setResourceDescriptor( path );
281286
handshake.put( "Host", host );
287+
if (headers != null) {
288+
for (Map.Entry<String, String> kv : headers.entrySet()) {
289+
handshake.put(kv.getKey(), kv.getValue());
290+
}
291+
}
282292
conn.startHandshake( handshake );
283293
}
284294

0 commit comments

Comments
 (0)