Skip to content

Commit

Permalink
Added parser for HTTP headers
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodivisi0n committed Jun 27, 2012
1 parent 20bf42c commit 68e8105
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Autobahn/src/de/tavendo/autobahn/WebSocketReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.HashMap;
import java.util.Map;

import android.os.Handler;
import android.os.Message;
Expand Down Expand Up @@ -532,6 +534,26 @@ private boolean processHandshake() throws UnsupportedEncodingException {
}
return res;
}

@SuppressWarnings("unused")
private Map<String, String> parseHttpHeaders(byte[] buffer) throws UnsupportedEncodingException {
// TODO: use utf-8 validator?
String s = new String(buffer, "UTF-8");
Map<String, String> headers = new HashMap<String, String>();

String[] lines = s.split("\r\n");
for (String line : lines) {
if (line.length() > 0) {
String[] h = line.split(": ");
if (h.length == 2) {
headers.put(h[0], h[1]);
Log.w(TAG, String.format("'%s'='%s'", h[0], h[1]));
}
}
}

return headers;
}


/**
Expand Down

0 comments on commit 68e8105

Please sign in to comment.