Skip to content

Commit 86898db

Browse files
committed
note accessing http headers
1 parent fd9b0c1 commit 86898db

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,39 @@ See the Javadoc for more details.
135135

136136
http://socketio.github.io/socket.io-client-java/apidocs/
137137

138+
### Transports and HTTP Headers
139+
You can access transports and their HTTP headers as follows.
140+
141+
```java
142+
// Called upon transport creation.
143+
socket.io().on(Manager.EVENT_TRANSPORT, new new Emitter.listener() {
144+
@Override
145+
public void call(Object... args) {
146+
Transport transport = (Transport)args[0];
147+
148+
transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() {
149+
@Override
150+
public void call(Object... args) {
151+
@SuppressWarnings("unchecked")
152+
Map<String, List<String>> headers = (Map<String, List<String>>)args[0];
153+
// modify request headers
154+
headers.put("Cookie", Arrays.asList("foo=1;"));
155+
}
156+
});
157+
158+
transport.on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() {
159+
@Override
160+
public void call(Object... args) {
161+
@SuppressWarnings("unchecked")
162+
Map<String, List<String>> headers = (Map<String, List<String>>)args[0];
163+
// access response headers
164+
String cookie = headers.get("Set-Cookie").get(0);
165+
}
166+
});
167+
}
168+
});
169+
```
170+
138171
## Features
139172
This library supports all of the features the JS client does, including events, options and upgrading transport. Android is fully supported.
140173

0 commit comments

Comments
 (0)