From 3159edb108d4426c351c3a3e9dcde61764b21704 Mon Sep 17 00:00:00 2001 From: Felix Bechstein Date: Sun, 8 Nov 2009 22:21:38 +0100 Subject: [PATCH] fix socket fuckup, was: fauilure in protocoll --- src/de/ub0r/android/adBlock/Proxy.java | 38 ++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/de/ub0r/android/adBlock/Proxy.java b/src/de/ub0r/android/adBlock/Proxy.java index 2ea8b6c..e9f97a2 100644 --- a/src/de/ub0r/android/adBlock/Proxy.java +++ b/src/de/ub0r/android/adBlock/Proxy.java @@ -159,9 +159,9 @@ public class Proxy extends Service implements Runnable { } catch (IOException e) { // FIXME: java.net.SocketException: Broken pipe // no idea, what causes this :/ - Connection c = Connection.this; + // Connection c = Connection.this; String s = new String(buf, 0, read); - Log.e(TAG, null, e); + Log.e(TAG, s, e); } } } @@ -228,7 +228,16 @@ public class Proxy extends Service implements Runnable { return null; } String line = new String(buf, 0, avail); - buffer.append(line); + String testLine = line; + int i = line.indexOf(" http://"); + if (i > 0) { + // remove "http://host:port" from line + int j = line.indexOf('/', i + 9); + if (j > i) { + testLine = line.substring(0, i + 1) + line.substring(j); + } + } + buffer.append(testLine); strings = line.split(" "); if (strings.length > 1) { // TODO: read rest of line @@ -251,18 +260,8 @@ public class Proxy extends Service implements Runnable { path = strings[1]; } // read header - int i; - avail = reader.available(); String lastLine = line; - String testLine; - while (avail > 0) { - if (avail > CopyStream.BUFFSIZE) { - avail = CopyStream.BUFFSIZE; - } - avail = reader.read(buf, 0, avail); - // FIXME: this may break - line = new String(buf, 0, avail); - buffer.append(line); + do { testLine = lastLine + line; i = testLine.indexOf("\nHost: "); if (i >= 0) { @@ -282,7 +281,16 @@ public class Proxy extends Service implements Runnable { } lastLine = line; avail = reader.available(); - } + if (avail > 0) { + if (avail > CopyStream.BUFFSIZE) { + avail = CopyStream.BUFFSIZE; + } + avail = reader.read(buf, 0, avail); + // FIXME: this may break + line = new String(buf, 0, avail); + buffer.append(line); + } + } while (avail > 0); } else { Log.d(TAG, "unknown method: " + strings[0]); } -- 2.11.4.GIT