From 86898db7b19a6d82098a50e57f8c89db4f77be37 Mon Sep 17 00:00:00 2001 From: nkzawa Date: Thu, 15 Oct 2015 01:56:18 +0900 Subject: [PATCH] note accessing http headers --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 67d0cd7..fe90ac1 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,39 @@ See the Javadoc for more details. http://socketio.github.io/socket.io-client-java/apidocs/ +### Transports and HTTP Headers +You can access transports and their HTTP headers as follows. + +```java +// Called upon transport creation. +socket.io().on(Manager.EVENT_TRANSPORT, new new Emitter.listener() { + @Override + public void call(Object... args) { + Transport transport = (Transport)args[0]; + + transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() { + @Override + public void call(Object... args) { + @SuppressWarnings("unchecked") + Map> headers = (Map>)args[0]; + // modify request headers + headers.put("Cookie", Arrays.asList("foo=1;")); + } + }); + + transport.on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() { + @Override + public void call(Object... args) { + @SuppressWarnings("unchecked") + Map> headers = (Map>)args[0]; + // access response headers + String cookie = headers.get("Set-Cookie").get(0); + } + }); + } +}); +``` + ## Features This library supports all of the features the JS client does, including events, options and upgrading transport. Android is fully supported.